whats wrong here(im new)

This is a discussion on whats wrong here(im new) within the C Programming forums, part of the General Programming Boards category; #include <stdio.h> void main() { char me[20]; printf("Name your zodiac sign babey:"); scanf("%s",&me); printf("So your a %s too!\n",me); }...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    4

    Post whats wrong here(im new)

    #include <stdio.h>


    void main()
    {
    char me[20];

    printf("Name your zodiac sign babey:");
    scanf("%s",&me);
    printf("So your a %s too!\n",me);
    }

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    Code:
    #include <stdio.h> 
    
    int main() 
    { 
    	char me[20]; 
    
    	printf("Name your zodiac sign babey:"); 
    	scanf("%s",&me); 
    	printf("So your a %s too!\n",me); 
    
    	return 0;
    }
    main always return an int. Other then that it compiled and runed fine for me.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    4
    thanx

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Actually you're both wrong.

    > scanf("%s",&me);

    This is wrong.

    scanf( "%s", me );

    This is right. The reason is that the name of an array is a pointer to its first element. Scanf takes a pointer. Not the address of a pointer.

    Quzah.
    Last edited by quzah; 05-15-2002 at 03:23 PM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21