Advertisement

07.19.2008 at 10:27AM PDT, ID: 23579244
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

sscanf in c problem

Asked by jeffiepoo in C Programming Language

Tags: , ,

Ok, so my problem is, I am trying to use sscanf to get a string and a floating point number, however for some reason it is missing the floating point number altogether. I used BOTH fputs AND printf in the following example to illustrate what IS getting scanned in, and what is SUPPOSED to be getting scanned in. I will include the output as well. Thanks for the help guys. (This is not the whole program, this is just the guts of the function), I NEED THAT FLOATING POINT NUMBER SCANNED IN!  A list of things I have tried is at the very bottom too.

FILE *file_input;
  file_input=fopen(filename,"r");
  if (file_input == NULL){
    return 1;}
    double a;
    char string [100];
    char temp_string[30];
    while (fgets(string,sizeof(string),file_input)!=NULL){
      sscanf(string,"%s\t%f",temp_string,&a);
      fputs(string, stdout);
printf("%s\t%f\n", temp_string,&a);

OUTPUT:
sneffels> a.out example.txt
PLANET  AU
PLANET  0.000000
Mercury 0.39
Mercury 0.000000
Venus   0.72
Venus   0.000000
Earth   1
Earth   0.000000
Mars    1.52
Mars    0.000000
Jupiter 5.20
Jupiter 0.000000
Saturn  9.54
Saturn  0.000000
Uranus  19.18
Uranus  0.000000
Neptune 30.06
Neptune 0.000000
Pluto   39.44
Pluto   0.000000
PLANET  AU
PLANET  0.000000
Mercury 0.39
Mercury 0.000000
Venus   0.72
Venus   0.000000
Earth   1
Earth   0.000000
Mars    1.52
Mars    0.000000
Jupiter 5.20
Jupiter 0.000000
Saturn  9.54
Saturn  0.000000
Uranus  19.18
Uranus  0.000000
Neptune 30.06
Neptune 0.000000
Pluto   39.44
Pluto   0.000000

I've tried sscanf(string,"%s\t%f",temp_string,a);   but I get a segfault
Ive tried sscanf(string,"%s%f",temp_string,&a);   without the tab character still no luck
I've tried sscanf(string,"%s %f",temp_string,&a); with just a space and that doesn't work either.Start Free Trial
[+][-]07.19.2008 at 10:30AM PDT, ID: 22043132

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:36AM PDT, ID: 22043147

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: c, C scripting, C scripting
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.19.2008 at 10:37AM PDT, ID: 22043150

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:40AM PDT, ID: 22043159

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:42AM PDT, ID: 22043164

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:42AM PDT, ID: 22043165

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:43AM PDT, ID: 22043170

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:44AM PDT, ID: 22043175

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:45AM PDT, ID: 22043180

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:49AM PDT, ID: 22043197

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:52AM PDT, ID: 22043206

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:53AM PDT, ID: 22043208

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 10:58AM PDT, ID: 22043220

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 11:01AM PDT, ID: 22043227

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.19.2008 at 11:02AM PDT, ID: 22043229

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 11:03AM PDT, ID: 22043233

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 11:05AM PDT, ID: 22043241

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 11:36AM PDT, ID: 22043308

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628