hi all, this is a piece of code from the program that i`m currently working on.. -
.
-
.
-
#define SIZE 10
-
.
-
.
-
.
-
int opt, NumARR[SIZE], L, MaxINT, sum=0, input_int;
-
-
char *FileNameSTR[20];
-
FILE *fileP;
-
.
-
.
-
.
-
-
// Option 2 'File I/O'
-
else if(opt==2) {
-
-
// Read from file
-
printf("Enter a file name to read: ");
-
gets(*FileNameSTR);
-
-
if((fileP=fopen("FileNameSTR","r"))==NULL)
-
printf("\n> Specified file not found!\n\n");
-
-
else {
-
printf("Integers in file:\n");
-
for(L=1;L<=SIZE;L++)
-
fscanf(*FileNameSTR,"%d",&NumARR[L]);
-
-
-
while(!feof(FileNameSTR[20])) {
-
for(L=1;L<=SIZE;L++) { printf("%d\n",NumARR[L]); }
-
}
-
fclose(FileNameSTR);
-
printf("\n> Reading process done.\n\n");
-
} // end of else
-
-
-
// Write to file
-
printf("Enter a file name to read: ");
-
gets(*FileNameSTR);
-
-
if((fileP=fopen("FileNameSTR","w"))==NULL)
-
printf("\n> Specified file not found!\n\n");
-
-
else {
-
for(L=1;L<=SIZE;L++) {
-
printf("Int #%d: ",L);
-
scanf("%d",&NumARR[L]);
-
}
-
-
while(!feof(stdin)) {
-
for(L=1;L<=SIZE;L++) { fprintf(FileNameSTR,"%d\n",NumARR[L]); }
-
}
-
fclose(FileNameSTR);
-
printf("\n> Reading process done.\n\n");
-
} // end of else
-
-
} // end of if(2)
-
this code should ask
1- a filename to read 10 lines of integers from that file, then prints them to screen
2- a filename to write 10 integers from keyboard to that new file but there is a problem on getting the file name, which is (i think) about pointer related..
Dev-C gives these errors:
"[Warning] passing arg 1 of `fscanf' from incompatible pointer type "
"[Warning] passing arg 1 of `fclose' from incompatible pointer type "
"[Warning] passing arg 1 of `fprintf' from incompatible pointer type "
"[Warning] passing arg 1 of `fclose' from incompatible pointer type " any help will be appreciated, thanks in advance.. 2 1682
Hi. It may work better if you declare your file string like this:
Then use it like this:
and this: - fscanf(FileNameSTR,"%d",&NumARR[L]);
willakawill, thank you very much for the help, especially char FileNameSTR[50] part.
for other errors, i handled with them by replacing function args as fileP , which is defined as a pointer to the file.
and modified code is above, no syntax error, but now there is a problem about reading file: "it never stops reading" -
.
-
.
-
#define SIZE 10
-
.
-
.
-
.
-
int opt, NumARR[SIZE], L, MaxINT, sum=0, input_int;
-
-
char FileNameSTR[20];
-
FILE *fileP;
-
.
-
.
-
.
-
// Option 2 'File I/O'
-
else if(opt==2) {
-
-
// Read from file
-
printf("Enter a file name to read: ");
-
fflush(stdin); // skip gets() without flush
-
gets(FileNameSTR);
-
-
if((fileP=fopen(FileNameSTR,"r"))==NULL)
-
printf("\n> Specified file not found!\n\n");
-
-
else {
-
printf("Integers in file:\n");
-
for(L=1;L<=SIZE;L++)
-
fscanf(fileP,"%d",&NumARR[L]);
-
-
-
while(!feof(fileP)) {
-
for(L=1;L<=SIZE;L++) { printf("%d\n",NumARR[L]); }
-
}
-
fclose(fileP);
-
printf("\n> Reading process done.\n\n");
-
} // end of else
-
-
-
// Write to file
-
printf("Enter a file name to read: ");
-
gets(FileNameSTR);
-
-
if((fileP=fopen(FileNameSTR,"w"))==NULL)
-
printf("\n> Specified file not found!\n\n");
-
-
else {
-
for(L=1;L<=SIZE;L++) {
-
printf("Int #%d: ",L);
-
scanf("%d",&NumARR[L]);
-
}
-
-
while(!feof(stdin)) {
-
for(L=1;L<=SIZE;L++) { fprintf(fileP,"%d\n",NumARR[L]); }
-
}
-
fclose(fileP);
-
printf("\n> Reading process done.\n\n");
-
} // end of else
-
-
} // end of if(2)
-
i think i can handle with this; but any better solutions and suggestions will be appreciated, thanks again. Sign in to post your reply or Sign up for a free account.
Similar topics
by: matt dittman |
last post by:
I have created a windows service that reads emails from a
drop directory and moves them to the appropriate mail
folder every 15 seconds. I can move, rename and delete
the files as needed, up...
|
by: Michael Bøcker-Larsen |
last post by:
Hi
I'v been stuck on this problem for ages now. I have found that I'm not
the only one with this problem, by looking through the different
newsgroups.
Hope you can help me! I know there is a...
|
by: Kenneth Keeley |
last post by:
Hi,
I have a page that uploads files to my server and I wish to display a
"Please wait while uploading" page to the user while the file is uploading.
I have been able to redirect the user once the...
|
by: Jim |
last post by:
Hi, I have an assembly and it's satellite in my GAC.
I have referenced the DLLs in my project (from the same location where I
added it to the GAC). CopyLocal is set false.
When I run the...
|
by: rdemyan via AccessMonster.com |
last post by:
My application has a lot of complicated SQL statements, calculations,
processing that takes time. I've created a custom form to act like a
messagebox. It has 10 small rectangles on it that change...
|
by: cassbiz |
last post by:
Could use some help here.
This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working????
from the form I want to carry over two lines of...
|
by: Ty |
last post by:
Hello all,
I am creating a web site with Visual Stuido 2008. I am trying to use
a java script file to create a busybox for login from this page
http://blogs.crsw.com/mark/articles/642.aspx.
I...
|
by: Steveaux |
last post by:
Hi, I'm new to ASP.Net, so this may be something simple that I
forgot. I have a form where a person can create a login. I'm doing
the processing on this myself. The form has a plethora of...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |