answersLogoWhite

0

#include #include intsearch(char[],char[]); void main() { char a[100],b[40]; int loc; printf("\n Enter the main string :"); gets(a); printf("\n Enter the search string :"); gets(b); loc = search(a,b); if(loc==-1) printf("\nNot found"); else printf("\nFound at location %d",loc+1); getch(); } int search(char a[],char b[]) { int i,j,k; i=0,j=0; while(a[i]!='\0') { while(a[i]!=b[0] && a[i]!='\0') i++; if(a[i]=='\0') return(-1); //search can not continue k=i; while(a[i]==b[j] && a[i]!='\0' && b[j]!='\0') { i++; j++; } if(b[j]=='\0') return(k); if(a[i]=='\0') return(-1); i=k+1; j=0; } }

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
RossRoss
Every question is just a happy little opportunity.
Chat with Ross

Add your answer:

Earn +20 pts
Q: Substring in c without string functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp