Originally Posted by
csharp100
Not at all, I am trying that as we speak. Just trying to understand it that is all. I really appreciate your help. Thank you!
Works good till a point, it prints out the output but then it stops working or other words the program does not exit on its own. I get a windows error and I am using codeblocks with the gcc compiler. Just Tried it on our unix system and I am getting a segmentation fault. Here is my code.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
int main()
{
FILE *fP;
char str[N], *c;
char *gpa = strchr(str, ' ');
if ((fP = fopen("names.dat", "r")) == NULL)
{
printf("%s not opened", "names.dat");
exit(EXIT_FAILURE);
}
do {
c = fgets(str, N ,fP);
char *gpa = strchr(str, ' ');
*gpa++ = '\0';
printf("%s\t%s\n", str, gpa);
}
while (c != NULL);
fclose(fP);
return 0;
}