![]() |
| | #1 |
| Registered User Join Date: Jan 2010
Posts: 54
| How do I input and print out a list of names Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0;
char *iName[1][4] = {'\0'};
int iChoice = 0;
while(iChoice != 3)
{
system("cls");
printf("\n1\tEnter a name");
printf("\n2\tPrint Report");
printf("\n3\tQuit");
printf("\n\n\tEnter a Choice: ");
scanf("%d", &iChoice);
if(iChoice == 1)
{
system("cls");
printf("\n\tEnter a name: ");
scanf("%s %s", iName[0],iName[1]);
}
else if(iChoice ==2)
{
break;
}
else if(iChoice == 3)
break;
}
system("cls");
for (i = 0; i <= 4; i++)
printf("%s %s",iName[0],iName[1]);
}
|
| artistunknown is offline | |
| | #2 |
| Registered User Join Date: Feb 2010
Posts: 4
| char *iName[1][4] is a mulidimensional array of pointers to chars. Why not just have an array of pointers to chars like this: Code: char *iName[4] //This will store 4 pointers to chars (4 strings) Code: if(iChoice == 1)
{
system("cls");
printf("\n\tEnter a name: ");
scanf("%s", iName[0]) //Store the first string;
}
|
| Cameron2 is offline | |
| | #3 |
| Registered User Join Date: Jan 2010
Posts: 54
| Well I might be able to figure that out but I'm suppose to learn how to use a multdimensional array the program is suppose to teach me how to use them |
| artistunknown is offline | |
| | #4 |
| Registered User Join Date: Feb 2010
Posts: 4
| Fair enough. I still don't see why you need a multidimensional array of pointers to chars, how about you just do this: Code: char iName[Number of Strings you want - 1][Length of string + 1] Code: char iName[1][4]; |
| Cameron2 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking array for string | Ayreon | C Programming | 87 | 03-09-2009 03:25 PM |
| singly linked circular list | DarkDot | C++ Programming | 0 | 04-24-2007 08:55 PM |
| Linked List Help | CJ7Mudrover | C Programming | 9 | 03-10-2004 10:33 PM |
| Contest Results - May 27, 2002 | ygfperson | A Brief History of Cprogramming.com | 18 | 06-18-2002 01:27 PM |