[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Wrting to a file in C

Posted on 2002-04-09
5
Medium Priority
?
289 Views
Last Modified: 2010-04-15
Hi
here is the code that i am trying to write or how i am trying to write into file

FILE *file
out = fopen("C:\myText.txt", "W");
fprintf(out, "Temprature");
fprintf(out, "%d\n", Voltage);
fclose(file);

but i can't get it to work, could somebody please tell me what i am doing wrong, and fix the problem for me. thanks

regards
Dewaana
0
Comment
Question by:Dewaana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:leflon
ID: 6928455
first you mixed variable names file and out
then you better check if fopen was successful, and you should use wt for the access type

->
FILE* file;
if(file=fopen("c:\mytext.txt","wt")!=NULL)
{
/* do some output */
 fclose(file);
}

this should work

leflon
0
 
LVL 7

Accepted Solution

by:
leflon earned 120 total points
ID: 6928462
better:
if((file=fopen("c:\mytext.txt","wt"))!=NULL)

leflon
0
 

Author Comment

by:Dewaana
ID: 6928558
Thank you very much, i think that if statment did the trick :)

Dewaana
0
 
LVL 1

Expert Comment

by:Aenox
ID: 9209314
lol, that wasn't the problem. This was:

FILE *file;
0
 
LVL 1

Expert Comment

by:Aenox
ID: 9209328
FILE *out;
out = fopen("C:\\myText.txt", "W");
fprintf(out, "Temprature");
fprintf(out, "%d\n", Voltage);
fclose(out);
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question