Need help

This is a discussion on Need help within the C Programming forums, part of the General Programming Boards category; I want to make a decision based program based on what words the user inputs and I want the program ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    35

    Exclamation Need help

    I want to make a decision based program based on what words the user inputs and I want the program to check the user inputs against specific requirements then make another decision if these specific requirements are met, if they are I want the program to first output it to the screen then secondly I want it to save it in a folder called requirements met, if the requirements aren't met I want the program to again output it to the screen including the reasons it didnt meet the requirements before storing it into a file called requirements not met

    Hope someone can help GRG

    *edit* the specific requirements are:
    the word is no long that 10 letters and must not contain numbers
    Last edited by geekrockergal; 01-29-2009 at 10:03 AM.

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    What have you tried so far?

    Post your code and we can look at it and offer advice.
    I would guess its basic file IO operations and input/output
    I'm just trying to be a better person - My Name Is Earl

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I would tackle this one thing at a time. All of it can be done with seperate functions called from main, for example:
    Code:
    int main() {
            input=getuserinput();
            condition=checkinput(input);
            if (condition==x) printtofile(input);
            else showonscreen(input);
    }
    One of the decisions you have to make is whether the function which gets the user input should also check it, or whether it should be checked by another function. The second way is better, since then you could have more than one kind of check function but probably only need a single, generic get-input function.

    So the first thing you should try and do is write the getinput function and make sure it returns correct info back to main -- a possible sketch:
    Code:
    char *getinput() {
      the function
    }
    
    int main() {
            char input[256];   // size as appropriate
            input=getinput();
            printf("%s\n",input);
            return 0;
    }
    Once you have this working, it will be easy to add more functions to complete the rest of your specifications.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by swgh View Post
    What have you tried so far?

    Post your code and we can look at it and offer advice.
    I would guess its basic file IO operations and input/output
    ya see ... the thing is when I look at examples of code I get confused very easily if there arent comments or anything so I havent written any code yet but Ive been practising code I might need

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by MK27 View Post
    I would tackle this one thing at a time. All of it can be done with seperate functions called from main, for example:
    Code:
    int main() {
            input=getuserinput();
            condition=checkinput(input);
            if (condition==x) printtofile(input);
            else showonscreen(input);
    }
    One of the decisions you have to make is whether the function which gets the user input should also check it, or whether it should be checked by another function. The second way is better, since then you could have more than one kind of check function but probably only need a single, generic get-input function.

    So the first thing you should try and do is write the getinput function and make sure it returns correct info back to main -- a possible sketch:
    Code:
    char *getinput() {
      the function
    }
    
    int main() {
            char input[256];   // size as appropriate
            input=getinput();
            printf("%s\n",input);
            return 0;
    }
    Once you have this working, it will be easy to add more functions to complete the rest of your specifications.
    Thanks but it confusing my little brain

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by geekrockergal View Post
    Thanks but it confusing my little brain
    As it should

    Code:
    char input[256];   // size as appropriate
    input=getinput();
    you cannot assign to array

    moreover - you have already a standard function for reading strings in C
    it is called fgets, so just use it where appropriate
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by vart View Post
    As it should
    it doesnt take much

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by geekrockergal View Post
    it doesnt take much
    you can start with reading the FAQ
    for example there is

    FAQ > How do I... (Level 1) > Get a line of text from the user/keyboard (C)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by vart View Post
    you can start with reading the FAQ
    for example there is

    FAQ > How do I... (Level 1) > Get a line of text from the user/keyboard (C)
    Thank you

Popular pages Recent additions subscribe to a feed

Tags for this Thread


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