Thread: String assignments

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    You need to:

    a. Read the tutorial on this site
    b. Go to this new web site called Google, search for "strings in c", and actually visit some of the links that are returned from that search and read them.

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Sorry, just found it, disregard that last question please. Thanks.

  3. #18
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    K, so valid question time.
    If I use
    Code:
    fgets ( string, 50, stdin );
    will other FILE* pointers interfere with that? Because that is all that I can think of that is causing my compiler to "Unexpectedly Quit. Would you like to send an Error Report?" and I don't know what else would be doing it.

  4. #19
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by mcotter222 View Post
    K, so valid question time.
    If I use
    Code:
    fgets ( string, 50, stdin );
    will other FILE* pointers interfere with that? Because that is all that I can think of that is causing my compiler to "Unexpectedly Quit. Would you like to send an Error Report?" and I don't know what else would be doing it.
    Your COMPILER is crashing? That's never your fault, even if your code is wrong.

  5. #20
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    The %s specification with scanf stops at the first white space character after the first "word".

    You can use scanf() to pick up blanks too, but the syntax is a bit different for the format specifier.

    See here:
    http://www.cppreference.com/stdio/scanf.html

    For instance, if you want to pick up all (up to) 80 characters up to and not including the newline, code:
    Code:
    char response[81] ; 
    scanf("%80[^\n]", response ) ;
    Mainframe assembler programmer by trade. C coder when I can.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by mcotter222 View Post
    K, so valid question time.
    If I use
    Code:
    fgets ( string, 50, stdin );
    will other FILE* pointers interfere with that? Because that is all that I can think of that is causing my compiler to "Unexpectedly Quit. Would you like to send an Error Report?" and I don't know what else would be doing it.
    It should be
    fgets(string, sizeof(string), stdin)

    And try a rebuild first and foremost. Sometimes compilers can get into a "bad state" and require a cleanup. I've encountered that with Visual Studio some times.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    Quote Originally Posted by Elysia View Post
    And try a rebuild first and foremost. Sometimes compilers can get into a "bad state" and require a cleanup. I've encountered that with Visual Studio some times.
    How do I try that?

    And it works for other programs, just not that one, and when I take that part out, it works again.

  8. #23
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    If you're using one of the Microsoft compilers, like Visual C++ Express, you should be able to clean from the Build menu, like Build -> Clean Solution, or something similar. Then you just recompile and relink like usual. Other IDEs have this option somewhere, try the help documents.

  9. #24
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    I got it to work with:
    Code:
    char response[81] ; 
    scanf("%80[^\n]", response ) ;
    Thanks for the help, and I will rebuild if it crashes again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM