There is really important wrong, but I couldnt find

  • Thread starter emre esirik(hacettepe computer science and enginee
  • Start date
E

emre esirik(hacettepe computer science and enginee

struct guitar active;
char *buffer_char3;
while(!feof(ptdata))
{
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);


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);

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

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

Martin Ambuhl

emre said:
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.
 
T

Tor Rustad

emre esirik(hacettepe computer science and engineering) wrote:

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

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

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

Posting a minimal self-contained example, demonstrating the "problem",
will generate more useful help.

My guess is, you should look into how strtok() works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top