========orderStudent.txt=========
student01 99
student02 88
student03 77
===================
25 C:\..........countStudent2.c [Warning] passing arg 2 of `strcat' makes pointer from integer without a castCode:#include<stdio.h> #include<string.h> main() { FILE *fp; fp = fopen("orderStudent.txt","r"); char ch; int showTxt =-1; char marks[200] = {'0','0','0'}; int count; char str1[] = "hello"; char str2[] = " 123"; char str3[] = "str2:"; while( (ch = fgetc(fp))!=EOF ) { if(ch == ' ') {showTxt = 0; count=0; } if(ch == '\n') { strcat(str1,str2); // correct strcat(str3,marks[2]); // incorrect printf("\t%s\n",str3); printf("\t%c%c",marks[1],marks[2]); showTxt = -1; } if((showTxt ==0)&&(count>0)) { marks[count] = ch; printf("%c",marks[count]); } ++count; } fclose(fp); printf("\n\n"); system("PAUSE"); return 0; }
================================================== ===========================
hello everyone , This is my first post on this forum.
I am a student learning C,
I know what happen to the program, but i don't know how to solve it
marks[2] - make the problem, it is a single number got from the txt file, such as 8,7
but...
1. char ch; ==> then ch is in type of char?
2. so, ch = fgetc(fp) , all ch will be in char type?
3. so, when marks[2] = ch, not matter marks[2] is something, such as 1,2,3,4,... all should be char
from 1-3 , is what i think. any thing wrong?
if marks[2] is type char?
why ? strcat(str3,marks[2]); will make the program error
tell you more, as before i test , marks[2] is a int.
Please anyone can help me ?
but don't change to much for the program if it is not necessary, unless the program work but i don't understand.
i know if marks[2] is a char , then all problem is solved.
help me pro.



LinkBack URL
About LinkBacks


