Thread: storing a name with no extra characters

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    36

    storing a name with no extra characters

    HI guys,
    this is just a fun little program im kinda bored and working on learning more about C, anyways the program is just supposed o mess with a couple of my buddies so it looks like kinda intelligent lol anyway my question is how can i make it so when they enter thier name and i store that as a variable how can i get that to display like i have it below in the program ive tried; int. float, char, what can i do to have this display a name without any extra characters or cutting off their names?

    Code:
    #include<stdio.h>
    int main(void)
    {
    int a, b;
    printf("hello, im CPU, by Russ the first program to express emotions! Whats your name?\n");
    scanf("%d", &a);
    
    printf("\nnice to meet you", a);
    printf("\nHows your day going so far?");
    scanf("%d", &b);
    Thanks guys

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    A needs to be a string.... Like this...
    Code:
    #include<stdio.h>
    int main(void)
    {
       char a[32];
       printf("hello\nI'm CPU, by Russ\n The first program to express emotions!\n Whats your name?  : ");
       scanf("%s", a);
    
       printf("\nnice to meet you %s", a);
       printf("\nHows your day going so far?");
    
      return 0;
    }
    Last edited by CommonTater; 02-25-2011 at 12:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with reading characters
    By csvraju in forum C Programming
    Replies: 4
    Last Post: 03-31-2009, 07:59 AM
  2. Replies: 12
    Last Post: 02-21-2009, 02:55 AM
  3. Removing Specific Characters from Strings
    By gfmartin05 in forum C++ Programming
    Replies: 4
    Last Post: 02-09-2009, 09:53 AM
  4. ascii characters video displaying on tv screen
    By deian in forum C Programming
    Replies: 6
    Last Post: 10-12-2004, 09:46 PM
  5. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM

Tags for this Thread