Hi all,
I'm completely new to C but have dabbled with Bash scripting before. I've been trying to get my head around pointers etc.
I have a small routine to check for the existence of a string in a file and print to screen, I claim no originality it's a mish mash of what's on net. i hope it's a start of a larger program eventually so I want it to be simple.
Now, it did work, just once and was correct, matching the string in a file but since then it refuses to work.
I'm puzzled as to why. If anyone can point me in right direction.
Here's the code I have :-
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
int main() {
char SearchText[]="#!/bin/ash"; /* Search String. */
char MainText[80];
if ((fp = fopen("/etc/rc.d/rc.local","r")) == NULL) { return; }
while (feof(fp) == 0)
{ fgets( MainText,80,fp );
if (strcmp(MainText,SearchText) == 0 )
printf("strings are equal\n");
else
printf("strings are different\n");
printf("%s", MainText); /* See what MainText actually is */
}
fclose(fp);
return(0);
}