Thread: 2Dimensional arrays..read from txt file PROBLEM! :O

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2013
    Location
    San Jose, CA
    Posts
    53
    Ohhh, so then how do i change it to read characters?

  2. #2
    Registered User hex_dump's Avatar
    Join Date
    Dec 2012
    Posts
    88
    Quote Originally Posted by kal123456 View Post
    Ohhh, so then how do i change it to read characters?
    look up the scanf and fscanf function. What is the format specifier for reading characters?

    once you have that you can put your print statement to print out CHARACTERS, right after you read it in to see if its reading properly. Changed your code and it working on my system.
    Last edited by hex_dump; 01-30-2013 at 09:53 PM.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Location
    San Jose, CA
    Posts
    53
    Ohh ok, so I changed the %d to %c which means that now it should be printing characters instead of integers. However, now it doesn't output anything, just a blank space haha.....what do you mean by making my print statement to print out characters?....

  4. #4
    Registered User hex_dump's Avatar
    Join Date
    Dec 2012
    Posts
    88
    Quote Originally Posted by kal123456 View Post
    Ohh ok, so I changed the %d to %c which means that now it should be printing characters instead of integers. However, now it doesn't output anything, just a blank space haha.....what do you mean by making my print statement to print out characters?....
    give your printf statment the same specifier as you did for scanf
    Code:
    for(i=0;i<row;i++)  {
         for(j = 0; j < col; j++){
             fscanf(fp,"%c", &namesArray[i][j]);
             printf("%c", namesArray[i][j]);
        }
    }

  5. #5
    Registered User
    Join Date
    Jan 2013
    Location
    San Jose, CA
    Posts
    53
    OMG.........it actually works!!!! only now, the last problem, how do I get it to look exactly like the txt file? like this:

    Code:
    16
    Kelly, Victor       
    Lam, Gary           
    Nagasake, David     
    Nguyen, Jeff        
    Nguyen, Michael     
    Sinn, Scott         
    Smith, Jacob        
    Son, Thai           
    Tavares, Maribel    
    Tran, Diane         
    Tsukamoto, Andrew   
    Wang, Mary          
    Young, Daniel       
    Wells, Steve        
    Wong, Justin        
    Johnson, Mary
    cause right now, it looks like this:

    Code:
    16Kelly,VictorLam,GaryNagasake,DavidNguyen,JeffNguyen,MichaelSinn,ScottSmith,Jac
    obSon,ThaiTavares,MaribelTran,DianeTsukamoto,AndrewWang,MaryYoung,DanielWells,St
    eveWong,JustinJohnson,Mary
    
    
    
    
    Process returned 0 (0x0)   execution time : 0.297 s
    Press any key to continue.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read data from file into 2 dimensional arrays help
    By khoavo123 in forum C Programming
    Replies: 4
    Last Post: 02-02-2012, 02:30 AM
  2. Reading Picture file into 2dimensional data array?
    By DiscoStu9 in forum C Programming
    Replies: 10
    Last Post: 08-25-2009, 06:03 PM
  3. passing 2dimensional arrays to functions
    By owi_just in forum C Programming
    Replies: 1
    Last Post: 04-25-2005, 08:08 AM
  4. Replies: 4
    Last Post: 01-30-2005, 04:50 AM

Tags for this Thread