设计ï¼
1. åè¡åæ¾ãstudent.txtä¸æ¯è¡åæ¾ä¸ä¸ªå¦ççå项信æ¯ï¼å³ä»¥æ¢è¡ç¬¦ä¸ºåºå«åæ¡å¦çä¿¡æ¯ã读åçæ¶åä»æ件ä¸æ¯æ¬¡æåä¸è¡æ¥åå±æ§å¤æï¼å¹¶çéï¼
2. tabéå±æ§ãå½ç¶ä¹å¯ä»¥ä»¥å
¶ä»ç¬¦å·ï¼ä½ä¸è¬æ¥è¯´ï¼å¨å¦çä¿¡æ¯å
容ä¸ï¼ä¸è¬ä¸ä¼ä½¿ç¨table符å·ï¼åå¯ä»¥ç¨table符å·æ¥å¨æ¯è¡å¦çä¿¡æ¯ä¸åéæ¯é¡¹å±æ§ï¼å¦å·ãå§åçï¼ï¼è¿
æ ·å¯ä»¥éè¿è·è¿ä¸ä¸ªæå¤ä¸ªtable符å·ï¼æ¾å°å
³å¿çå±æ§ï¼å¹¶è¿è¡å¤æï¼ä½å头4个åèæ¯å¦æ¯â广å·âãæ§å«å±æ§æ¯å¦ä¸ºâ女âçï¼ãåæ¶ä¹å¯ä»¥å¨è¾åºæ¶éæ©è¾åºé¨åå±æ§äºã
å
³é®ä»£ç ï¼
//1. read a single line from a file
char* getFileLine(FILE *argInputFile, char *argLine){
int c;
... ...
for(int i = 0; (c = getc(argInputFile)) != EOF && c != '\n'; i++){
argLine[i] = c;
}
argLine[i] = '\0';
... ...
return argLine;
}
//2. read a single property from the information line
/**
* @param *argStuInfo: some student's information which was read by function 'getFileLine()'
* @param argPropertyNo: the position of the property to be read. e.g.:
* if the properties's order is like this: StuNo. (\t)Name(\t)Gender(\t)Addr(\t)others
* in the student info, and you want to read the gender of this student, then
* you should call this function like this: getProperty(stuInfoLine, 3, gender);
*/
char* getProperty(const char *argStuInfo, const int argPropertyNo, char *argProperty){
... ...
count = 1;
for(int i = 0; (c = getc(argInputFile)) != '\0' && count < argPropertyNo; i++){
if(c == '\t'){
count++;
}
}
for(int i = 0; (c = getc(argInputFile)) != '\0' && c != '\t'; i++){
argProperty[i] = c;
}
argProperty[i] = '\0';
return argProperty;
}
没æ£æ¥åç¼è¯è¿ï¼å·®ä¸å¤å°±æ¯è¿æ ·äºãæäºè¿äºå½æ°å°±å¯ä»¥å¤æ类似ä½å头4个åèæ¯å¦æ¯â广å·âãæ§å«å±æ§æ¯å¦ä¸ºâ女âçè¿äºæ¡ä»¶äºã
psï¼cä¸å¯¹æ件çæä½ï¼
stdio.h头æ件ä¸å®ä¹äºå¯¹æ件çå¼ç¨ç±»åï¼FILE åå
¶åºæ¬æä½ï¼
#include <stdio.h>
...
FILE *filePointer
filePointer = fopen("c://student.txt", "rw");
int ch = getc(filePointer);
putc('a', filePointer);
温馨提示:答案为网友推荐,仅供参考