Quick Question

This is a discussion on Quick Question within the C Programming forums, part of the General Programming Boards category; I appologize but i have not taken a C class in a couple of years and now that i am ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    3

    Quick Question

    I appologize but i have not taken a C class in a couple of years and now that i am taking one I encountered a problem.

    I am given the following two files which I am not allowed to modify using gcc on a unix server:
    ****p1.c *******
    Code:
    #include "getword.h"
    int main()
    {
    int c;
    char s[STORAGE];
    for(;;) {
            printf("n=%d, s=[%s]\n", c = getword(s), s);
            if (c == -1) break;
            }
    }
    ***getword.h****
    Code:
    #include <stdio.h>
    #include <string.h>
    
    #define STORAGE 255
          /* This is one more than the max wordsize that getword() can handle */
    
    int getword(char *w);
    **************************************************

    i have to write getword.c which gets one word from the input stream and returns -1 iff EOF is encountered otherwise it returns the number of characters in the word

    i can pass an input from the user from getword.c using fgets() however , how can this input be stored into the already declared char s[STORAGE] in p1.c ?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    how can this input be stored into the already declared char s[STORAGE] in p1.c ?
    p1.c passes the "array" to the function ("getword"), so that the function can modify it however you want. This seems to be a pretty strange function, but thats another story.

    Basically, in "getword" you get the input (up to the given max. size, ensuring you do not overflow), and store it in "w", which you can freely modify. Then return the number of characters in the string, depending on the given specific word.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    3
    got it ! thanks

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    3

    Cool

    hehe its funny that our real names are both our reversed usernames

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    :P
    Easiest way to remember a username! (Apart from our actual first names, which usually aren't available).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

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