Thread: What's wrong here?

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    What's wrong here?

    Code:
    #include <stdio.h>
    
    int input;
    char msg[128];
    
    void decrypt()
    {
    	int i = 0;
    	while(i<128)
    	{
    		scanf("%i",input);
    		if(input == 30)
    			msg[i] = 0x41;
    		else if(input == 02)
    			msg[i] = 0x42;
    		else
    			return;
    		i++;
    	}
    }
    int main()
    {
    	decrypt();
    	printf("\n");
    	return 0;
    }
    I think that it's a scanf() problem, yet I get no errors when I compile. What do you think?

  2. #2
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    I think that it's a scanf() problem
    scanf("%d",&input);

  3. #3
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    Oh!

    Crud! I forget that... it's been so long since I use scanf(). Thanks!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    To obtain numbers properly, read this:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    >>msg[i] = 0x41;
    This isn't good practice, don't use hex numbers like that. This is much easier on the eyes, and more portable:
    >>msg[i] = 'A';
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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, 10: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, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM