开发者

How do I place 2-3 digit numbers obtained from a file into an array? [closed]

It's difficult to tell what is being asked here. Thi开发者_JAVA百科s question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
main ()
{
        FILE *pRead;
        FILE *pWrite;
        char lastname [20];
        char firstname [20];
        char grade [4];
        char gradefi [4];
        char gradeltr [3];
        int i=0;

        pRead=fopen ("testtext.dat", "r");

        if (pRead == NULL || pWrite == NULL)
                printf ("\nFile cannot be opened\n");
        else
                printf ("\nContents of testtext.dat\n\n");
                fscanf (pRead, "%[^,]%[^\n]%s", lastname, firstname, &grade);
                printf ("\n");
                pWrite=fopen ("report.txt", "w");
                fprintf (pWrite, "%s %s %s\n", firstname, lastname, &grade);
        while (!feof(pRead))
                {
                        ++i;
                        printf ("%s %s %s\n", firstname, lastname, &grade);
                        fscanf(pRead, "%[^,]%[^\n]%s", lastname, firstname, &grade);
                        fprintf (pWrite, "%s %s %s\n", firstname, lastname, &grade);
                }

fclose(pRead);
fclose(pWrite);

printf ("\nThere are %d student(s) in this list\n", i);


Well, not to look like an old stale paranoid fart or anything, but I suggest you put some curly brackets around the consequent statments after else and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜