Re: There is really important wrong, but I couldnt find



emre esirik(hacettepe computer science and engineering) wrote:
struct guitar active;
char *buffer_char3;
while(!feof(ptdata))
^^^^^^^^^^^^
This is almost certainly _not_ what you want. Why is this Pascalism so common? It can't be that any competent C textbook actually suggests it.
{
fgets(buffer[0],26, ptdata);
fgets(buffer[1],26, ptdata);
fgets(buffer[2],26, ptdata);
fgets(buffer[3],26, ptdata);
fgets(buffer[4],26, ptdata);

Each of the above should be checked for success.
You don't show a declaration of buffer, so I assume it is an array of char arrays, each of adequate length. Check to make sure.



active.serial=integer_analys(buffer[0]);
active.price=integer_analys(buffer[1]);

buffer_char = strtok (buffer[2], bracket);
buffer_char = strtok (NULL, bracket);


buffer_char2 = strtok (buffer[3], bracket);
buffer_char2 = strtok (NULL, bracket);


buffer_char3 = strtok (buffer[4], bracket);
buffer_char3 = strtok (NULL, bracket);

It is rarely right to use strtok on your only copy of a string, since it is destructive. Note that an array of
char *buffer_char[5];
would parallel the (assumed) declaration of
#define BIGENOUGH 27
char buffer[5][BIGENOUGH];
and allow the use of loops for processing.
Also note that you have destroyed the first values returned by strtok assigned to the buffer_char* by the second calls.

how can I convert buffer_char3 to active.model ( model is char
array of guitar struct component)

buffer_char3 points to a string. You want to store it in a char array. Doesn't the extremely obvious copy using any of the strcpy, strncpy, memcpy, or memmove function work for you.

I have tried to find for 4 days, I did everything but I couldnt
help me please

I suspect that you are confused about _what_ you are trying to do. Get that straight before even thinking about _how_ to do it.
.



Relevant Pages

  • Re: confusion when comparing char * with a string literal
    ... strtok need a char * as it's first argument. ... x is an array, not a constant pointer. ... out as an array of char or a pointer to constant string. ...
    (comp.lang.c)
  • There is really important wrong, but I couldnt find
    ... fgets(buffer,26, ptdata); ... buffer_char2 = strtok (NULL, bracket); ... how can I convert buffer_char3 to active.model (model is char ...
    (comp.lang.c)
  • details in my previous Q?????
    ... to me is that when i had used the function (strtok) ... from the library...i sent it a char* beside the delimiter ... char* and a const char* as arguments.....so why that erroe did ... appear??and when i tried with an array instead,it worked fine..... ...
    (comp.lang.cpp)