Thread: need string help

  1. #1
    Registered User
    Join Date
    Apr 2008

    need string help

    printf ("Title >");
    scanf ("%s", ctlg[x].title);
    printf ("Title :%s \n", ctlg[i].title);

    i've typed the program above to do a program on library catalog. When I type "The best book", the scanf function works well but when i wanted to print it back using the printf function, the title became "The".. can anyone help?

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    1) Do not flush stdin.
    2) Do not read strings with scanf.
    3) Use fgets.
    4) Your app will work.
    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.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    fflush(stdin) is undefined, read this FAQ

    scanf stops at white space, read this FAQ
    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.

  4. #4
    Registered User
    Join Date
    Apr 2008
    u guys helped a lot..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 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