Password problem

This is a discussion on Password problem within the C Programming forums, part of the General Programming Boards category; I am stuck on this program. I have to get 3 numbers as strings;convert them to integers,reverse there order,then use ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    6

    Password problem

    I am stuck on this program. I have to get 3 numbers as strings;convert them to integers,reverse there order,then use tokenization to separate them. I can't seem to get the numbers reversed to begin qwith. Any help would be great! Thanks!
    Code:
    #include <stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    
    int convertNum ( const char *);
    
    main()
    
    {
      char myString[10];
      char myString2[10];
      char myString3[10];
      char myStringfull[80];
      int x;
    
    void reverse (const char * const);
    
      printf("Enter a three digit number:\n ");
      scanf("%s",&myString);
      printf("Enter another three digit number:\n");
      scanf("%s",&myString2);
      printf("Enter one more number:\n");
      scanf("%s",&myString3);
    
    strcpy(myStringfull,myString);
    strcpy(myStringfull,myString2);
    strcpy(myStringfull,myString3);
    
    x=convertNum(myStringfull);
    
    
      return 0;
    
    }
    int convertNum (const char * myStringfull)
    {
    	int y;
    	reverse(myStringfull);
    
    	y= atoi(myStringfull);
    
    	
    
    	return y;
    }
    
    void reverse (const char * const sPtr)
    {
    	if (sPtr[0] == '\0')
    		return;
    	else 
    	{
    		reverse(&sPtr[1]);
    		putchar(sPtr[0]);
    	}
    }


    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    in your reverse function it A) doesn't make sense B) won't work because your string is a constant and you can't edit constants.

    Now, maybe you should try to work out how to reverse a string on paper before you start coding, and then your functions may make some sense.

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    strcpy(myStringfull,myString);
    strcpy(myStringfull,myString2);
    strcpy(myStringfull,myString3);
    If you want top copy ALL strings into myStringfull, you need to use the strcat function on myString2 and myString3 to append the string to myStringfull.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A tenet connection from a C program..
    By ahmd2080 in forum Linux Programming
    Replies: 2
    Last Post: 07-04-2009, 04:42 AM
  2. Password Program
    By lukesowersby in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 12:36 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 02:04 AM
  5. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 06:20 AM

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