PDA

Click to See Complete Forum and Search --> : problem with code


MPrestonf12
Feb 5th, 2001, 01:57 PM
I can not get this code to work i've tried everything!!

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main(void)
{
char mystr;
char *p;
char retval;

printf("%s\n", "enter letter");

scanf("%s", mystr);

p = &mystr;

retval = *p;

printf(retval);

system("pause");
return 0;
}

parksie
Feb 5th, 2001, 02:00 PM
The problem is that char only allocates ONE CHARACTER. You need to have an array:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main(void) {
char mystr[20];

printf("Enter letter: ");
scanf("%s", mystr);
printf("%s", mystr);

system("pause");
return 0;
}