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; }



LinkBack URL
About LinkBacks



