I am trying to make this function keep going on until I call an interrupt or, delete function in my GCC. HEre is what I have. I tried putting a while(1) loop in my driver.c but it does not stop.
Code:
#include <stdio.h>
int sreplace(char newc, char oldc, char *s)
{
int cnt;
cnt = 0;
while(*s !='\0') //loop to run till the end of the string
{
if(*s == oldc) //if the char found which to be replaced
{
*s = newc; //replace
cnt++;
}
s++;
}
return cnt;
}
Code:
#include <stdio.h>
char *strmatch(char *str, char *s)
{
char *tmp;
while(*str!='\0'){
tmp = s;
while(*tmp !='\0' && *str == *tmp)
{
str++;
tmp++;
}
if(*tmp =='\0')
{
return str;
}
str++;
}
return(NULL);
}
Code:
#include <stdio.h>
int sreplace(char newc, char oldc, char *s);
char *strmatch(char *str, char *s);
int main()
{
char line1[1024];
char line2[1024];
char *ptr;
char *s1, *s2;
fgets((s1=line1),1024,stdin);
fgets((s2=line2),1024,stdin);
sreplace('\0','\n', line1);
sreplace('\0','\n', line2);
ptr = strmatch(s1,s2);
printf("%s\n",ptr);
return 0;
}
Comment