Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with inputting multidimensional string arrays....
#1
Hi. I am very new to c/c++ and I need some help. Can someone show me how to make a program that has a mulidimensional array of strings so I can keep a list of names, and then input x ammount of names. So, I would have like a prompt that says "How many names do you wan't to enter: " and then you type in the names and then you go through a for loop statement and type all the names. Then it would show each name you typed in. Here's what I have so far (but I can't even get it to run because I don't know what I'm doing):

Code:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
    int number;
    int i;
    char tname[100];

    printf("How many names do you want to enter: ");
    scanf("%d", &number);
    
    char *names[number];
    for(i=0,i<number,i++)
    { names=(char *) malloc (100); }
    
    for(i=0,i<number,i++)
    {
        printf("Name %d: ", i);
        scanf(" %s", &tname);
        strcpy(names[i], &tname);
    }

    while (!kbhit()) {}
    free(names);
    return 0;
}

also, what is stdafx.h
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply


Messages In This Thread
Help with inputting multidimensional string arrays.... - by typosoft - 06-18-2003, 02:35 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)