Originally Posted by
peterderijp
that's because i use the Visual C++ compiler i though
Your compiler has actually TWO compilers: 1 for C++ (which you are using now), and one for C (which you should be set to use for files that have a dot c extension in their filename.
You can set that a a default setting in your Visual program. The keystrokes I've forgotten, but something like Projects tab >> default properties >> compiler options, and etc.
<stdafx.h> is unknown to C, and would be an error or a warning, at least.
So dump that line.
This is what I was thinking of. Taken from your posted code, and adding a few bits.
Code:
#include <stdio.h>
#include <string.h>
int main (void){
int i, r;
char *p = NULL;
char str[100];
char str2d[12][5];
FILE *fp = NULL;
fp = fopen("c:\\months.txt", "r");
//check if we can access the file, if not, return 1
if( fp == NULL ){
printf ("cannot open file");
return 1;
}
r=0; //r=row, set to zero at start
while((fgets(str, sizeof(str), fp))!= NULL) {
//find the next comma
if(p==NULL) {
p=strtok(str, ",");
strcpy(str2d[r++], p);
}
while((p=strtok(NULL, ","))!=NULL) {
//put the word, into the array
strcpy(str2d[r], p);
printf("\n%s", str2d[r++]);
getchar();
}
}
fclose(fp);
printf("\n\n\t\t\t press enter when ready");
(void) getchar();
return 0;
}