Thread: I am stumped...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Unhappy I am stumped...

    Ok guys. This is my first post so i hope you are willing to help this cutie out a bit. here is my problem. I have been trying forever to be able to take an array fill it with user input and then take that array and break it up into all its different words.

    ex.

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>

    typedef struct {
    char word;
    int times;
    }WORK;

    main()
    {
    WORK part[50];
    int num1=0,num2=0, num3,num5,num6=0, num7=0;
    char ch,ch1,string[200], charstore[50];

    printf("\n Please enter a some words\n");
    gets(string);

    num3=strlen(string);
    scanf("%c%c", &ch,&ch);

    num3--;
    while (num1<=num3) //string to upper
    { //
    ch1=string[num1]; //
    string[num1]= toupper (ch1); //
    // printf("%s\n", &string[num1]); //
    num1++; //end string to upper
    }
    num1=0;
    num3++;
    while (num1<=num3)
    {printf("%d\n",num1);
    num5=0;
    if (string[num1] <= '@'|| string[num1] >= '[')
    {
    num1++;
    num5=1;
    }
    if (num5 == 0)
    {
    charstore[num6]=string[num1];
    num1++;
    num6++;

    }
    if (num5==1)
    {

    if (num6 !=0)
    {
    charstore[num6] = '\0';
    printf("\n%s",&charstore);

    // here is were i need code to make change from array to struct


    num6=0;
    num7++;
    num1++;
    }
    else
    num1++;
    }

    }
    scanf("%c%c", &ch,&ch);
    }



    after this ... i want to be able to have the amount of times each word was in the array.

    and if you are really in the mood... to help that is i am wondering how i can take all the words from the struct and alphabetize them.
    Thanks
    Heather [email protected]

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    I have been trying forever to be able to take an array fill it with user input and then take that array and break it up into all its different words.
    Get the string. You could use 'gets' but this is rather unsafe because the length of the input could extend beyond the size of the array. It would be better to use 'fgets' because you can control the amount of characters that you want to accept. Otherwise use dynamic allocation and reallocation, but this is getting advanced.

    After you have the string than tokenize it with 'strtok'. Try looking up this function in your compilers help menu. It gives a good example and it is a little tricky but not too difficult to use. You should familiarize yourself with a basic understanding of pointers if you do not have this already.
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. syntax stumped. simple.
    By CodeMonkey in forum C++ Programming
    Replies: 2
    Last Post: 03-04-2009, 06:36 PM
  2. Can someone help me im totally stumped
    By Joe123 in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2005, 12:17 PM
  3. totally stumped
    By sand_man in forum C Programming
    Replies: 6
    Last Post: 08-22-2004, 07:12 PM
  4. Writing a "Protocol" - Stumped.
    By mrpickle in forum Game Programming
    Replies: 8
    Last Post: 01-21-2004, 07:37 PM
  5. help with stl search/find, or something else- stumped!
    By Terranc in forum C++ Programming
    Replies: 3
    Last Post: 12-21-2002, 04:11 PM