Helppp

This is a discussion on Helppp within the C Programming forums, part of the General Programming Boards category; im doin a program for school but i have no idea how to started......if anyone could help me get started ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    Lightbulb Helppp

    im doin a program for school but i have no idea how to started......if anyone could help me get started it would be great thanksss!!!!!

    program:
    there are 3 texts
    the program must output

    - How many words in the text?
    - How many characters ? (count all characters, including spaces and punctuation)
    - What is the longest word in the text?
    - How many sentences?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    So what have you tried so far?
    What previous programs have you written so far?
    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.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    Its been quite a long since I don't write anything about strings...but have you tried using libraries that can handle strings?...
    I am not sure but i think one is strings.h ... if I am not mistaking...

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Ok, most of the stuff you're asking for can be covered by some clever uses of fgets and sscanf.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Logical Aesthetician codepoet's Avatar
    Join Date
    Nov 2006
    Posts
    14
    Quote Originally Posted by GQgirl
    - How many words in the text?
    - How many characters ? (count all characters, including spaces and punctuation)
    - What is the longest word in the text?
    - How many sentences?
    - use two loops, one with fgets() to loop through the sentences, and one with strtok() to split each sentence into words
    - total_words variable that increments by 1 inside the 2nd loop as you find each word
    - total_chars variable that increments by strlen(cur_sentence) inside your first loop after each sentence
    - longest_word variable that keeps track of the largest number from comparisons beween longest_word and strlen(cur_word) inside 2nd loop as you find each word
    - total_sentences variable that increments by 1 inside the 1st loop as you read each sentence

  6. #6
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    I hope this helps!

    Try to understand this and you can do your program. Read about string.h and about the strlen fuction in any c book.

    Code:
    // This an example i found in one of my c books. Is this helps?
    #include <stdio.h>
    #include <string.h>      /* provides strlen() prototype */
    #define PRAISE "What a super marvelous name!"
    int main(void)
    {
      char name[40];
    
      printf("What's your name?\n");
      scanf("%s", name);
      printf("Hello, %s. %s\n", name, PRAISE);
      printf("Your name of %d letters occupies %d memory cells.\n",
             strlen(name), sizeof name);
      printf("The phrase of praise has %d letters ",
             strlen(PRAISE));
      printf("and occupies %d memory cells.\n", sizeof PRAISE);
      return 0;
    }
    Wise_ron
    One man's constant is another man's variable

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    dont use scanf to read a string, instead use fgets()

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get() Helppp!!!
    By yukapuka in forum C++ Programming
    Replies: 6
    Last Post: 05-03-2008, 12:57 PM
  2. helppp in bank databse
    By neha007 in forum C++ Programming
    Replies: 1
    Last Post: 06-02-2007, 10:43 AM
  3. SC_HANDLE Helppp!
    By Bazzz in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2002, 06:23 AM
  4. Modem programming helppp amateur!!
    By Siagal in forum Windows Programming
    Replies: 4
    Last Post: 10-12-2001, 04:02 AM
  5. Modem programming helppp amateur!!
    By Siagal in forum C Programming
    Replies: 4
    Last Post: 10-10-2001, 06:12 AM

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