954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Filing example

hello guys,

here is another problem on filing. it creates the intended files and it is saving as well. but the problem is the numbers become invisible this time in those files. it is showing . . . (dots) instead of even numbers or odd numbers. Anyone has got any idea why it is showing like that? here is the log

#include<stdio.h>
main()
{
FILE *f1,*f2,*f3;
int number,i;
printf("contents of DATA file \n\n");
f1=fopen("DATA","w");/*create data file*/
for (i=1;i<=30;i++)
{
scanf("%d",&number);
if (number==-1)break;
putw(number,f1);
}
fclose(f1);
f1=fopen("DATA","r");
f2=fopen("ODD","w");
f3=fopen("EVEN","w");

while ((number=getw(f1))!=EOF)/*Read from DATA file*/
{
if(number%2==0)
putw(number,f3);/*"write a EVEN file"*/
else                       
putw(number,f2);/*"write a ODD file"*/
}
fclose(f1);
fclose(f2);
fclose(f3);
f2=fopen("ODD","r");
f3=fopen("EVEN","r");
printf("\n\n contents of ODD file\n\n");
while((number=getw(f2))!=EOF)
printf("%d",number);
printf("\n\n contents of EVEN file\n\n");
while((number=getw(f3))!=EOF)
printf("%4d",number);
fclose(f2);
fclose(f3);
getch();
}
The Buzzer
Newbie Poster
7 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

I think its about time you learn to use code tags, even though you have already been told to use them before and ignored what was said. Try again with code tags..

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

Hmm, I thought I was in the C++ forum.

Oh, I am!

This C code works for me, I see the numbers. How are you viewing the resulting data files?

Keep in mind that putw() is writing an int to the file, not the ASCII values representing the numbers.

vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
 

Hmm, I thought I was in the C++ forum.

Oh, I am!

This C code works for me, I see the numbers. How are you viewing the resulting data files?


its like a dot dot (......) in the notepad, don't know why

The Buzzer
Newbie Poster
7 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Read my last line again. Then examine your output file(s) in a hex editor.

(No programmer should leave home without one.)

vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
 

Read my last line again. Then examine your output file(s) in a hex editor.

(No programmer should leave home without one.)

x

thanx for replying

what do u want me to do?

delete those putw() codes?
if i delete those then it will not show the results
so any other idea?

how can i examine output files in hex editor, can u explain. pls note i am using dev C++ and os is vista.

Regards

The Buzzer
Newbie Poster
7 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

I think i got that what i was searching for..!!
Can this code give me the values that user is entering ..??
So that i can trace what he has typed..?

Shaky Rox
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Shaky Rox, you've posted into a three-year-old thread, in general if you have a question about an inactive thread, copy any relevant info into a new thread.

Meanwhile, you can insert your own "printf()" statements if you wish to echo back what the user typed.

raptr_dflo
Practically a Master Poster
602 posts since Aug 2010
Reputation Points: 76
Solved Threads: 82
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You