Results 1 to 2 of 2

Thread: problem with code

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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;
    }
    Matt

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The problem is that char only allocates ONE CHARACTER. You need to have an array:
    Code:
    #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; 
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width