String Mess

This is a discussion on String Mess within the C++ Programming forums, part of the General Programming Boards category; My Task: to develop and test a C program to sort the letters in a string of characters read from ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    4

    String Mess

    My Task:

    to develop and test a C program to sort the letters in a string of characters read from the keyboard into alphabetical order.

    program should:

    a) Prompt the user to input a string of characters up to a maximum of 40 characters

    b) Read the string input from the keyboard

    c) Output the sequence of characters in alphabetical order

    d) Prompt the user to repeat the process if desired

    I have writtent the programme, and I get an error saying "eh.h is not in c++". Where am I going wrong?

    [tag]#include <iostream>
    #include <string>
    using namespace std;

    const int MAXSIZE = 9;
    char* names[MAXSIZE] = { "a", "c", "d", "f", "i", "b", "e", "g", "h" };
    char* tmp;

    void start();
    void decSort(char* arr[], int size);
    void ascSort(char* arr[], int size);
    void runAgain();

    int main()
    {

    I am sillystart();
    I am sillyreturn 0;
    }

    void start()
    {
    I am sillyint k, choice;
    I am sillycout << "Press 1 to sort in decending order: \n";
    I am sillycout << "Press 2 to sort in ascending order: \n";
    I am sillycin >> choice;

    I am sillyif(choice == 1)
    I am silly{
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillycout << "Before Sort: \n";
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillyfor(k = 0;k < MAXSIZE;k++)
    I am sillyI am sillycout << names[k] << "\n";

    I am sillyI am sillydecSort(names, MAXSIZE);
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillycout << "After Sort: \n";
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillyfor(k = 0;k < MAXSIZE;k++)
    I am sillyI am sillycout << names[k] << "\n";
    I am sillyI am sillyrunAgain();
    I am silly}

    I am sillyelse if(choice == 2)
    I am silly{
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillycout << "\nBefore Sort: \n";
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillyfor(k = 0;k < MAXSIZE;k++)
    I am sillyI am sillycout << names[k] << "\n";

    I am sillyI am sillyascSort(names, MAXSIZE);
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillycout << "\nAfter Sort: \n";
    I am sillyI am sillycout << "------------\n";
    I am sillyI am sillyfor(k = 0;k < MAXSIZE;k++)
    I am sillyI am sillycout << names[k] << "\n";
    I am sillyI am sillyrunAgain();
    I am silly}
    }

    void decSort(char* arr[], int size)
    {
    I am sillyfor(int i = 0; i < size - 1;i++)
    I am sillyfor(int j = 0; j < size - 1 - i;j++)
    I am silly{
    I am sillyI am sillyif(strcmp(arr[j], arr[j + 1]) < 0)
    I am sillyI am silly{
    I am sillyI am sillyI am sillytmp = arr[j];
    I am sillyI am sillyI am sillyarr[j] = arr[j + 1];
    I am sillyI am sillyI am sillyarr[j + 1] = tmp;
    I am sillyI am silly}
    I am silly}
    }

    void ascSort(char* arr[], int size)
    {
    I am sillyfor(int i = 0; i < size - 1;i++)
    I am sillyI am sillyfor(int j = 0; j < size - 1 - i;j++)
    I am sillyI am silly{
    I am sillyI am sillyI am sillyif(strcmp(arr[j], arr[j + 1]) > 0)
    I am sillyI am sillyI am silly{
    I am sillyI am sillyI am sillyI am sillytmp = arr[j];
    I am sillyI am sillyI am sillyI am sillyarr[j] = arr[j + 1];
    I am sillyI am sillyI am sillyI am sillyarr[j + 1] = tmp;
    I am sillyI am sillyI am silly}
    I am silly}

    }
    [/tag]
    Last edited by sikander; 05-18-2004 at 05:04 PM.

  2. #2
    Polar Fuzz
    Join Date
    Oct 2003
    Posts
    36
    Can you resubmit without the "I am silly" so that it will be easier to read?

  3. #3
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    you are indeed very silly
    .sect signature

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Code:
    int main()
    {
    	int tabTest;
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    4
    Quote Originally Posted by wbeasl
    Can you resubmit without the "I am silly" so that it will be easier to read?
    I am using Macintosh, and i do not know how it end up like that.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Wouldn't it be nice if all tab characters were changed to "I am silly" as well.......oh well.

    gg

  7. #7
    Registered User
    Join Date
    May 2004
    Posts
    4
    [code]:

    #include <iostream>
    #include <string>
    using namespace std;
    const int MAXSIZE = 9;
    char* names[MAXSIZE] = { "a", "c", "d", "f", "i", "b", "e", "g", "h" };
    char* tmp;
    void start();
    void decSort(char* arr[], int size);
    void ascSort(char* arr[], int size);
    void runAgain();
    int main()
    {
    start();
    return 0;
    }
    void start()
    {
    int k, choice;
    cout << "Press 1 to sort in decending order: \n";
    cout << "Press 2 to sort in ascending order: \n";
    cin >> choice;
    if(choice == 1)
    {
    cout << "------------\n";
    cout << "Before Sort: \n";
    cout << "------------\n";
    for(k = 0;k < MAXSIZE;k++)
    cout << names[k] << "\n";
    decSort(names, MAXSIZE);
    cout << "------------\n";
    cout << "After Sort: \n";
    cout << "------------\n";
    for(k = 0;k < MAXSIZE;k++)
    cout << names[k] << "\n";
    runAgain();
    }
    else if(choice == 2)
    {
    cout << "------------\n";
    cout << "\nBefore Sort: \n";
    cout << "------------\n";
    for(k = 0;k < MAXSIZE;k++)
    cout << names[k] << "\n";
    ascSort(names, MAXSIZE);
    cout << "------------\n";
    cout << "\nAfter Sort: \n";
    cout << "------------\n";
    for(k = 0;k < MAXSIZE;k++)
    cout << names[k] << "\n";
    runAgain();
    }
    }
    void decSort(char* arr[], int size)
    {
    for(int i = 0; i < size - 1;i++)
    for(int j = 0; j < size - 1 - i;j++)
    {
    if(strcmp(arr[j], arr[j + 1]) < 0)
    {
    tmp = arr[j];
    arr[j] = arr[j + 1];
    arr[j + 1] = tmp;
    }
    }
    }
    void ascSort(char* arr[], int size)
    {
    for(int i = 0; i < size - 1;i++)
    for(int j = 0; j < size - 1 - i;j++)
    {
    if(strcmp(arr[j], arr[j + 1]) > 0)
    {
    tmp = arr[j];
    arr[j] = arr[j + 1];
    arr[j + 1] = tmp;
    }
    }
    }

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    4
    here is the code without "I am silly". can you help me now.
    come on, guys pls help me out.
    Last edited by sikander; 05-18-2004 at 05:18 PM.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You forgot to define runAgain.
    My best code is written with the delete key.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    Bored by person who uses so much profanity in code and can't figure out code tags
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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