read characters till white space

This is a discussion on read characters till white space within the C Programming forums, part of the General Programming Boards category; Dear All, how to read read characters till white space Code: char *a; a =(char *)malloc(15); strcpy(a, "rollnumber 449"); char ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    but your malloc is not big enough to store 10 chars + nul-char

    1. scanf("%10s" should work

    2. strchr + strncpy

    3. strtok + strcpy
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 03:06 AM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 07:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 08: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

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