Storing chars to a buffer

This is a discussion on Storing chars to a buffer within the C Programming forums, part of the General Programming Boards category; Hi, I want to store chars from a file to buffer 'buf_P', when reachs zero char, I want to print ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    Storing chars to a buffer

    Hi,
    I want to store chars from a file to buffer 'buf_P', when reachs zero char, I want to print what is stored in the buffer and update the buf_P to hold new array of chars
    Code:
    ..
    ..
    char buf_P[300];
    int n;
    n=0;
    ..
    ..
    
    while((ch=getc(fp))!=EOF)
    {
    if(ch!=0)
    {
     //store it to buffer
     //buf_P[n]=ch;
     //n++;		
     }
    
    else
    {
    //print the string
    //update the buf_P
    }
    }..
    ..

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    How about filling in those ".."s for us. Your design seems poorly thought out, and some clarification of how the rest of the program works would go a long way toward us understanding some of your decisions.
    My best code is written with the delete key.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Code:
    while((ch=getc(fp))!=EOF)
    If you read the FAQ you'd learn that FEOF is not a char.FAQ

    what is ch. First, you assign it as a char then compare to an int later. Which may or may not be bad depending on what it is. The value of a promoted char is affected by its sign, and unfortunately, a char can be either signed or unsigned by default, this is compiler dependant.

    Also you told us what you want to do and you didn't ask a question. Are you expecting us to do it? Please rephrase and add full source code.
    Last edited by linuxdude; 07-04-2006 at 10:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Int storing two chars
    By nutsNguts in forum C Programming
    Replies: 3
    Last Post: 11-19-2008, 06:35 PM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. A Task Buffer for storing socket descriptors
    By cloudy in forum Networking/Device Communication
    Replies: 0
    Last Post: 09-09-2006, 01:08 PM
  4. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 04:15 AM

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