Link to home
Start Free TrialLog in
Avatar of kensy11
kensy11Flag for Belgium

asked on

how can i store data in to a array

hallo,
im trying to put data in to array its a name

but i dont know how

please help.
#include <stdio.h>
#include <conio.h>
int main (void)
{
 char vnaam[50];
printf("Wat is u voornam ?");
scanf("%s",vnaam[50]);
getchar();
printf("well look %s",vnaam[50]);
getchar();    
}

Open in new window

Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You don't need to specify the array index when writing to it:
#include <stdio.h>
#include <conio.h>
int main (void)
{
 char vnaam[50];
printf("Wat is u voornam ?");
scanf("%s",vnaam);
getchar();
printf("well look %s",vnaam);
getchar();    
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kensy11

ASKER

thanks my code looks like this

i have another question what if i dont know how long the array will be, now its 50 but can just leave it blank ?



#include <stdio.h>
#include <conio.h>
int main (void)
{
 char vnaam[];
printf("Wat is u voornam ?");
scanf("%s",vnaam);
getchar();
printf("well look %s",vnaam);
getchar();    
}

Open in new window

Avatar of phoffric
phoffric

>> char vnaam[];
Sorry, this is not valid. If you are filling up an array with scanf, you should make it much larger than any possible entry. After the entry, it will be null terminated.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not sure about scanf function but I remember that cin function in C++ takes 512 characters, not more.