Thread: Problem with I/O program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    No Tater, I think you're misunderstanding. He's passing a 2-d array to the function, which is demoted to a pointer to an array of 21 chars. He could also have written char textArray[][21]. Just like you can do char *foo or char foo[] for a 1-d array.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by anduril462 View Post
    No Tater, I think you're misunderstanding. He's passing a 2-d array to the function, which is demoted to a pointer to an array of 21 chars. He could also have written char textArray[][21]. Just like you can do char *foo or char foo[] for a 1-d array.
    OOPS... my bad. Sorry... I don't think I've ever seen it written like that before.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    19
    Code:
                 else if(in_word ==1)
                 {
                       textArray[i][j] = '\0';
                       i++;
                       j = 0;
                       in_word = 0;
                 }
        }
        first_word_total = i;   
      
        
        for(i = 0; i < first_word_total; i++)
        {
              for(j = 0; j != '\0'; j++)
              { 
                 textArray[i][j] = wordArray[i][j];
              }
        }
        
        for(i = 0; i < first_word_total; i++)
        {
              for(j = 0; j != '\0'; j++)
              {
                    printf("%s\n", wordArray[i]);
              }
        }
        
        //return word_total;
    I went back a put a null character at the end of the line, indicating the end of the string. Now when I run the program, it doesn't seem to copy anything, and only prints a blank list... It doesn't compare anything yet, but I'll get to that after I get the arrays to copy successfully. The bold part of the code is just to display the contents of wordArray, for debug purposes. So far nothing yet.

    I've tried single and double for loops so far, but to no avail...

    I'll try strcpy since there is now '\0' at the end of each line and see where that gets me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A C++ program problem.
    By hector_ronado in forum C++ Programming
    Replies: 1
    Last Post: 11-28-2009, 09:26 AM
  2. Having some problem with a GCF program
    By Requinex in forum C++ Programming
    Replies: 2
    Last Post: 08-08-2009, 09:59 AM
  3. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  4. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM
  5. problem with program
    By classicrockcj in forum C Programming
    Replies: 3
    Last Post: 11-21-2003, 01:00 AM