# "pointer from integer without a cast" & percentage problem

Page 1 of 1

## 2 Replies - 2324 Views - Last Post: 16 February 2011 - 07:16 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=216659&amp;s=aaf9d3cb09d30d80c18d554aceba7321&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jasminetea

Reputation: 0
• Posts: 2
• Joined: 16-February 11

# "pointer from integer without a cast" & percentage problem

Posted 16 February 2011 - 05:51 PM

Instructions:

In the file quizin1.dat (which you should cp to your directory), each
line represents a voting card of a registered voter. The character '1'
in the i-th indicates that the vote was cast for the i-th candidate. The
first 10 columns were for ten candidates for the Governor of California.
The names of these candidates are in the input file quizin2.dat (cp it to

Open the files quizin1.dat and quizin2.dat by using the file
pointers *finput1 and *finput2. Use the file pointer *foutput1 for the
output file quizout1.dat. Read the file quizin1.dat by using fgets().
Count the total number of voting cards, and the number of votes
cast for each of ten candidates. Use a character array: votes[80]
for votes, and an integer array: cand[10] for the candidates.
Print these results on the screen, and the numerical results in the output
file quizout1.dat. The printout on the screen should be as shown below,
while the file quizout1.dat should contain integers cand[0], cand[1],
..., cand[9] (either in one line or in separate lines).

Close the input file quizin1.dat and the output file quizout1.dat.

Then, open the created output file quizout1.dat for reading by
using the file pointer *finput3. Read the numerical data from this
file by using while(fscanf(finput3,...), and calculate the percentage
Within the while(fscanf(finput3),...) loop,
use fgets(cand_name,40,finput2) in conjunction with
sscanf(cand_name, "%s %s", name, surname) to scan the surname of the
candidate and make the printout on the screen and in the output file
quizout2.dat, poited to by the pointer *foutput2, as shown below.
Use the format %-16s when printing the string surname.

Close the files quizout1.dat and quizin2.dat.

...........................................................................

Total number of voting cards: 60

...........................
...........................
...........................

Percent votes for candidate Camacho is 11.67 %

.........................................................
.........................................................
.........................................................

Percent votes for candidate Tatro is 13.33 %
Percent votes for candidate Jordan is 8.33 %

Total percent votes for all candidates is 100.00 %
*/

My code so far:

```
#include<stdio.h>
int main(void)
{
FILE *finput1, *finput2, *finput3, *foutput1, *foutput2;
double percent, total_percent;

finput1 = fopen("quizin1.dat", "r");
finput2 = fopen("quizin2.dat", "r");
finput3 = fopen("quizout1.dat", "r");
foutput1 = fopen("quizout1.dat", "w");
foutput2 = fopen("quizout2.dat", "w");
printf("\n");

{

printf("\nTotal number of voting cards: %d\n\n",total_votes);
fprintf(foutput1, " \nTotal number of voting cards: %d\n\n",total_votes);

}
fclose(finput1);
fclose(finput2);
fclose(foutput1);

while(fscanf(finput3, "%-16s %lf", &surname, &percent)!=EOF)
{
sscanf(cand_name, "%-16s", surname);
cand_name++;

printf("Percent votes for candidate %-16s is %lf\n", surname, percent);
fprintf(foutput2, "Percent votes for candidate %-16s is %lf\n", surname,
percent);

total_percent+= percent;

printf("\nTotal percent votes for all candidates is %.2lf\n\n",
total_percent);
fprintf(foutput2, "\nTotal percent for all candidates is %.2lf\n\n",
total_percent
);

}
fclose(finput3);
fclose(foutput2);
}

```

What happens when I try to run it:

warning: passing argument 1 of 'sscanf' makes pointer from integer without
a cast

referring to the line: sscanf(cand_name, "%-16s", surname);

What I still need to figure out how to do:
1) How to get the % of votes for each candidate
2) How to have #s (1,2,3,4, etc.) instead of surnames for "Votes for
candidate 1: .. etc"
3) How to total up the number of percents for all candidates (unless what
I did was right?)
4) Does my program even make sense?

Is This A Good Question/Topic? 0

## Replies To: "pointer from integer without a cast" & percentage problem

### #2 jimblumberg

Reputation: 4892
• Posts: 15,280
• Joined: 25-December 09

## Re: "pointer from integer without a cast" & percentage problem

Posted 16 February 2011 - 06:51 PM

Also in future please post the complete error/warning message. These messages have information embedded in them to aid trouble shooting, like line number where the error is located.

For your error you might want to look at this link for scanf. Your first parameter (cand_name) is an int, the first parameter should be a const char *.

Jim

### #3 jasminetea

Reputation: 0
• Posts: 2
• Joined: 16-February 11

## Re: "pointer from integer without a cast" & percentage problem

Posted 16 February 2011 - 07:16 PM

jimblumberg, on 16 February 2011 - 06:51 PM, said:

Also in future please post the complete error/warning message. These messages have information embedded in them to aid trouble shooting, like line number where the error is located.

For your error you might want to look at this link for scanf. Your first parameter (cand_name) is an int, the first parameter should be a const char *.

Jim

I used that link & fixed the scanf part of my program & finally got my program to run. However, the output is:

Total number of voting cards: 1297

Total number of voting cards: 1643

Total number of voting cards: 1757

and it keeps repeating with different numbers for a long while. At the end, it says:

Total number of voting cards: 1675