Thread: only writes 'w' in new file

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Corvallis, OR
    Posts
    4

    only writes 'w' in new file

    Myfunction only writes w in the new file it creates. The number and spacing of the characters is correct, but it won't write the correct chars and ints.

    Any assistance is appreciated.

    Code:
    void readData(FILE *filename, student grades[], int len ){
       FILE *to= fopen("temp.txt", "w");
       char c;
       int i=0;
       while(fscanf(filename, "%c", &c) != EOF){
          if(c == ',' || c==10 || c==13){
             fprintf(to, " ");
          }
          else
          {
             fprintf(to, "%c", &c);
          }
       }
       fclose(filename);
       fclose(to);
    
       to= fopen("temp.txt", "r");
    
       while(fscanf(to, "%s %s %d %d %d", grades[i].last, grades[i].first, &grades[i].hw1, &grades[i].hw2, &grades[i].hw3) >0){
          i++;
    
       }
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
     fprintf(to, "%c", &c);
    That's what's wrong.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Corvallis, OR
    Posts
    4
    Thank you for the assist, it got me headed in the right direction and I got the rest of the program working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-11-2010, 12:05 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM