move chars position

This is a discussion on move chars position within the C Programming forums, part of the General Programming Boards category; hi! i would like to know how to move the chars input by user to diff chars? eg: user input ...

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

    move chars position

    hi! i would like to know how to
    move the chars input by user to diff chars?

    eg:

    user input string: abc
    user input an int(the position) : 3
    result will be : def

    ---------------------------------------------------------

    should i create an array for alpha={ 'A','B',C....XYZ};?
    then compare each chars in the string with alpha then add the int to print the output?
    < but how to load the string into an array?

    u get what i mean?
    btw i'm still new to C..

    thank u

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    I think your idea is correct. Check this pseudo-code to verify if I did understand you well.

    Code:
    get string
    get integer
    while not end of string
        get character
        determine index of character in alpha_array
        let index be index + integer
        replace character by alpha_array [index+integer]

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    7

    Thumbs up

    yep.. but how do i code the while part?

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Realise that the last character of a string is '\0'. Also realise that a string's characters can be accessed in this way:

    *(string+index])

    or

    string [index]

    So you need to declare an index which starts with 0 and is incremented in the while loop until the '\0' character is reached.

    Code:
    index = 0;
    while (string [index] != '\0')
    {
        ...
        index++;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe Comp Move help
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 09-24-2008, 12:05 PM
  2. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-03-2008, 12:10 AM
  3. Get char at position in textBox
    By Coding in forum C# Programming
    Replies: 2
    Last Post: 03-20-2008, 10:12 AM
  4. Getting the position of the mouse cursor
    By Mavix in forum Game Programming
    Replies: 5
    Last Post: 12-27-2007, 04:02 PM
  5. Replies: 5
    Last Post: 09-08-2001, 10:18 AM

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