string array reversing...

This is a discussion on string array reversing... within the C Programming forums, part of the General Programming Boards category; We allready posted a topic for turning around an String. But we are no experts, so we don't really understande ...

  1. #1
    cit
    cit is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    7

    Angry string array reversing...

    We allready posted a topic for turning around an String.
    But we are no experts, so we don't really understande the code that was posted....

    We need a EASY programm for converting a string:
    from (for example)
    ABCD --> DCBA

    We allready made this:
    #include "..\ownh.h"
    #include "..\stdio.h"


    int main (void)
    {
    /* Input of String-array *
    char mystring [21] ;
    printf ("fill in a string: ");
    scanf ("%s",mystring);
    printf ("The string you entered is: %s\n",mystring);

    /* Rotation of string */
    while (waarde1 > 0)
    {
    printf ("Rotation: %s\n",mystring+waarde1);

    waarde1 = waarde1--;
    }
    printf ("%s",uitk);


    pause ();
    return 0;
    }

    Now we have the problem that we cant select 1 sign from the string, but only from a sign.

    So we want to select each string value, and then paste them together in reverse angle....


    Please help us....
    No difficult C++ code (or the "strrev" command)... only this simple problem...

  2. #2
    Registered User dharh's Avatar
    Join Date
    Jan 2002
    Posts
    51
    Code:
    #include "..\ownh.h" 
    #include "..\stdio.h" 
    
    
    int main (void) 
    { 
    /* Input of String-array * 
    char mystring [21] ; 
    printf ("fill in a string: "); 
    scanf ("%s",mystring); 
    printf ("The string you entered is: %s\n",mystring); 
    
    /* Rotation of string */ 
    while (waarde1 > 0) 
    { 
    printf ("Rotation: %s\n",mystring+waarde1); 
    
    waarde1 = waarde1--;  
    } 
    printf ("%s",uitk); 
    
    
    pause (); 
    return 0; 
    }
    waarde1 = waarde1--; is unnecessary, just having waarde1--; will do the same thing.

    Not sure about your #includes, what kinda compiler you using and on what OS?

    printf ("%s",uitk); is also not going to work, uitk is never defined ever. For that matter neither is waarde1.

    What exactly is this rotation? Your trying to reverse a string right?

    Heres an example of what I would do.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    #define MAX 21
    
    int main(void) {
      char string[MAX];
      int size;
    
      printf("Give me a string foo: ");
      scanf("%s", string);
      printf("String entered is: %s\n", string);
      size = strlen(string);
      
      printf("Here is string in reverse: ");
      while (size >= 0) {
        printf("%c", string[size]);
        size--;
      }
    
      return 0;
    }

  3. #3
    cit
    cit is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    7
    We programm in Windows 98, A windows Compiler (version 12.0)
    linker version 6.0.

    We use a "homemade programm" to link in Dos..
    (Our teacher at school designed it..)
    He also made the pause () command. So the Dos prompt doesnt close (first press a key...)

    the programm you posted doesnt work, It goes through the compiler, but it the linker its stuck...

    The Strlen command is wrong..


    We dont know it anymore....

  4. #4
    Registered User dharh's Avatar
    Join Date
    Jan 2002
    Posts
    51
    What error does the linker give? strlen works perfectly fine for me? Might have something to do with how you did your #includes before.

    As for the pause thing, I use batch files to compile and execute my programs so I dont have to retype it everytime. In my batch file I include a pause so I dont have to put a pause in the program itself.

  5. #5
    cit
    cit is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    7
    We made it....
    Got a little help from our teacher....

    Here is the code:

    #include "..\ownh.h"
    #include "..\stdio.h"

    #define MAXCHAR 10

    int main (void)
    {
    /* Programma */
    char mystring [MAXCHAR];
    int ii = 0; /* aantal tekens */
    int aantal;

    printf ("voer string-waarde in: \n");
    scanf ("%s",mystring);

    while (mystring[ii] != '\0') ii++;


    while (ii>=0)
    {
    printf ("%c",mystring[ii-1]);
    ii--;
    }
    printf ("\n");

    pause ();
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 01:56 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. Reversing a String
    By ToasterPas in forum C++ Programming
    Replies: 10
    Last Post: 08-14-2001, 01:20 PM

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