Thread: Help needed (problem with basic C program)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    8

    Exclamation Help needed (problem with basic C program)

    Hello all,

    The other day I was experimenting with C and I stumbled across a problem in my program, it's a basic one for inputting names into a two dimensional array. That's all. But for some reason I fail to see there are problems everywhere! It's a basic program so I hope it's easy for experienced programmers to spot my amateur mistake.

    Comments are integrated throughout the program.

    Thanks for the help


    Code below:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
      typedef char names[50];/*defining a new type of variable called name which is a string of 50 chars*/
      typedef int namespaces[50];/*defining another variable called namepaces which is an array of 50 rows*/
      char namearr[namespaces][names];/*declaring an array of 50 rows and each row consists of a string of 50 chars*/
      
      printf("please enter the names you want in the file (limit is 50 names)"); /*Prompting the user for names to input in the array with a max of 50*/
      for (int i=0;i<50;i++){                                                   /*nested for loops for inputing individual values into the array*/
     for(int j=0; j<50 ; j++)
     prinf("Type name entry %d\n",i);
     scanf(%s,&namearr[i][j]);}
     
    
    for (int i=0;i<50;i++){        /*nested for loops for echo-ing the inputted strings*/
     for(int j=0; j<50 ; j++)
     printf("The names you inputted are input[%d][%d]",i,j,namearr[i][j]);
    } 
      
      system("PAUSE");	
      return 0;
    }
    Last edited by EpicYuzer; 11-11-2010 at 12:18 AM.

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