Thread: question

  1. #1
    Unregistered
    Guest

    question

    I just need some guidance about two things please

    1. Is reversing a string same as swaping it???
    can one use swap function for this purpose?

    2. I was supposed to alphatize the strings, and I used 'atof' and 'atoi' functions simultaneously. My compiler gave me some weired errors and didn't compile. I couldn't even undrstand those errors. Did I use the right functions??

    any kind of help is appreciated

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    #include<stdio.h>
    #include<string.h>
    void main()
    {
    char *m;
    char i,char1,char2;
    printf("your message:");
    scanf("%s",m);
    for(i=0;i<(strlen(m)/2);++i){char1=m[i];
    char2=m[strlen(m)-1-i];
    m[i]=char2;
    m[strlen(m)-1-i]=char1;
    }
    printf("%s",m);
    }
    it was for your first question
    i hope it's ok

    and for your second question
    you can use strcmp func. (string.h)
    it compares the strings with their ascii values

    strcmp(str1,str2)
    if str1 < str2 --> it returns a negative value
    if str1 = str2 --> it returns 0
    if str1 > str2 --> it returns a positive value

  3. #3
    Unregistered
    Guest
    Thanx kdt,
    I understand the first answer, but for the secong one, I'm supposed to alphabetize the strings. Like

    as if i have 4 strings. My job is to put those 4 strings into alphabetical order and renumber them appropriately.

    Please don't think that I don't wanna do my homework; I have been trying & trying, but I'm not a good programmar. Thank you very much for your anticipation.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    you can use an array for the strings
    and for example bubble sort to sort them
    think them like an integer but use strcmp() to sort them

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM