Thread: Help needed (problem with basic C program)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
     
    for(j=0;i<50;i++)  //use i not j, 
    {
     printf("Input %d is %s\n",i,namearr[i]);
    }
    Should help some.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    8
    Quote Originally Posted by Adak View Post
    Code:
     
    for(j=0;i<50;i++)  //use i not j, 
    {
     printf("Input %d is %s\n",i,namearr[i]);
    }
    Should help some.
    Yes thanks!


    The final successful code is:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
     int i,j;
      char namearr[50][50];
      
      printf("please enter the names you want in the file (limit is 50 names)");
      
      for(i=0;i<50;i++)
      {
     printf("Type name entry %d\n",i);
     scanf("%s",&namearr[i]);
     }
     
    
    for(j=0;j<50;j++)
    {
     printf("Input %d is %s\n",j,namearr[j]);
    } 
      
      system("PAUSE");	
      return 0;
    }
    But still I can't find a way to stop prompting the user for strings if he has entered some number of strings less than 50 and has no more to add.

    And still I don't understand why:

    Code:
    for(int i=0;i<50;i++)
    doesnt work or compile for that matter as a for loop and returns error mentioned earlier...

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by EpicYuzer View Post
    But still I can't find a way to stop prompting the user for strings if he has entered some number of strings less than 50 and has no more to add.
    Ok, here comes the "looking stuff up" part... Take a look at the stuff in your entries loop. Actually look them up in the C library documentation and study how they work... Does anything in that documentation suggest a way of ending the loop?

    Code:
    for(int i=0;i<50;i++)
    doesnt work or compile for that matter as a for loop and returns error mentioned earlier...
    That's because of the for (int i ... With the declaration inside the braces is a C-99 enhancement and you are not using a C-99 capable compiler.

    Yet another case for looking stuff up.

    Seriously... Do you know the 4 rules of computer bliss?

    1) Read the effing screen
    2) Read the effing help file
    3) Read the effing manual
    4) Ok, now you can ask your question.

    Seriously... This has been around for years and years... Ever heard RTFM... well, that's were it comes from.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    8
    Quote Originally Posted by CommonTater View Post
    Ok, here comes the "looking stuff up" part... Take a look at the stuff in your entries loop. Actually look them up in the C library documentation and study how they work... Does anything in that documentation suggest a way of ending the loop?



    That's because of the for (int i ... With the declaration inside the braces is a C-99 enhancement and you are not using a C-99 capable compiler.

    Yet another case for looking stuff up.

    Seriously... Do you know the 4 rules of computer bliss?

    1) Read the effing screen
    2) Read the effing help file
    3) Read the effing manual
    4) Ok, now you can ask your question.

    Seriously... This has been around for years and years... Ever heard RTFM... well, that's were it comes from.
    anduril462 already answered my question in an exceptional manner, and I didn't ask for any further clarification. So for you to comment in a childish manner is unneeded and rather useless.

    Thanks aundril462!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Problem with basic encryption program.
    By mmongoose in forum C++ Programming
    Replies: 5
    Last Post: 08-27-2005, 04:41 AM
  4. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  5. Replies: 5
    Last Post: 12-03-2003, 05:47 PM

Tags for this Thread