Page 1 of 1

4 Replies - 420 Views - Last Post: 10 December 2012 - 01:33 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=303450&amp;s=779ffd539bf0a601492c01836c10b661&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Livingjunk

Reputation: 0
• Posts: 7
• Joined: 13-November 12

Posted 10 December 2012 - 11:15 AM

```char temp[20];
sscanf(buffer, "%[^\n]", temp, buffer);
if(isdigit(temp[0]))// check if what read in is a digit
{
while(r < 8)
{
sscanf(temp, "%*d%d", olympians[i].base_values[r]);

for(int c = 0; c < 12; c++){
sscanf(temp, "%d", olympians[i].scores[r][c]);
tempScore[r] += olympians[i].scores[r][c];
}
tempScore[r] /= 12;
if((olympians[i].base_values[r]) <= 3.1){
tempScore[r] /= 2;
tempScore[r] += (olympians[i].base_values[r]);
}
else
tempScore[r] += (olympians[i].base_values[r]);

olympians[i].total_scores[i] += tempScore[r];
r++;
}
}

```

txt line im trying to read in:
1 7.5 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3

is something wrong with
```sscanf(temp, "%*d%d", olympians[i].base_values[r]);

```

because the compiler crash whenever i debugged this part

Is This A Good Question/Topic? 0

Replies To: Error in my read data

#2 Livingjunk

Reputation: 0
• Posts: 7
• Joined: 13-November 12

Re: Error in my read data

Posted 10 December 2012 - 11:25 AM

Livingjunk, on 10 December 2012 - 11:15 AM, said:

```char temp[20];
sscanf(buffer, "%[^\n]", temp, buffer);
if(isdigit(temp[0]))// check if what read in is a digit
{
while(r < 8)
{
sscanf(temp, "%*d%d", olympians[i].base_values[r]);

for(int c = 0; c < 12; c++){
sscanf(temp, "%d", olympians[i].scores[r][c]);
tempScore[r] += olympians[i].scores[r][c];
}
tempScore[r] /= 12;
if((olympians[i].base_values[r]) <= 3.1){
tempScore[r] /= 2;
tempScore[r] += (olympians[i].base_values[r]);
}
else
tempScore[r] += (olympians[i].base_values[r]);

olympians[i].total_scores[i] += tempScore[r];
r++;
}
}

```

txt line im trying to read in:
1 7.5 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3

is something wrong with
```sscanf(temp, "%*d%d", olympians[i].base_values[r]);

```

because the compiler crash whenever i debugged this part

nvm i see my error, why would olympians[i].name) work when reading string but why would i need &olympians[i].base_values[r]) for base value?

• Saucy!

Reputation: 6237
• Posts: 24,002
• Joined: 23-August 08

Re: Error in my read data

Posted 10 December 2012 - 12:55 PM

Without seeing your struct definition, I will assume that the name member is a C-string (an array of characters). The name of an array is a pointer to the first element of the array, so the & is not necessary. Other non-pointer variables require the & to give scanf the address of the variable to be written to.

EDIT: You said name was a string.

#4 Livingjunk

Reputation: 0
• Posts: 7
• Joined: 13-November 12

Re: Error in my read data

Posted 10 December 2012 - 01:11 PM

JackOfAllTrades, on 10 December 2012 - 12:55 PM, said:

Without seeing your struct definition, I will assume that the name member is a C-string (an array of characters). The name of an array is a pointer to the first element of the array, so the & is not necessary. Other non-pointer variables require the & to give scanf the address of the variable to be written to.

EDIT: You said name was a string.

```typedef struct skating
{
char name[MAX];
float base_values[MAX];
int scores[8][MAX];
float total_scores[MAX];
GOE execution;
}SKATING;

```

Here is my structure
so what you are saying is that SKATING olympians[MAX] point to name[0] so i dont need and & there but i do when i want to read in base_values and etc...?

#5 Livingjunk

Reputation: 0
• Posts: 7
• Joined: 13-November 12

Re: Error in my read data

Posted 10 December 2012 - 01:33 PM

```for(int c = 0; c < 12; c++)
{
sscanf(buffer, "%d%[^\n]", &olympians[i].scores[r][c]);
}

```

What is wrong with this code? i did the same thing for base_value and it work but scores doesn't read in -3 like i want it to.

This post has been edited by JackOfAllTrades: 10 December 2012 - 04:10 PM
Reason for edit:: Fixed code tags