Thread: read characters till white space

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    32

    read characters till white space

    Dear All,

    how to read read characters till white space

    Code:
    char *a;
    	a =(char *)malloc(15);
    	strcpy(a, "rollnumber 449");
    
    char *pvar,;
    pvar =(char *)malloc(10);
    now I need pvar as rollnumber (read till white space)




    Thanks ...

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    but your malloc is not big enough to store 10 chars + nul-char

    1. scanf("%10s" should work

    2. strchr + strncpy

    3. strtok + strcpy
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    32
    strtok() worked for me


    Thanks ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bytes lost with partial read in UDP
    By mynickmynick in forum Networking/Device Communication
    Replies: 3
    Last Post: 03-31-2009, 02:06 AM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. Galaxian or Space invaders for my next game (read this)
    By Leeman_s in forum C++ Programming
    Replies: 7
    Last Post: 11-07-2001, 09:28 PM