473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

file processing: custom name problem for i/o

revolter00
hi all, this is a piece of code from the program that i`m currently working on..

Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. #define SIZE 10 
  4. .
  5. .
  6. .
  7.     int opt, NumARR[SIZE], L, MaxINT, sum=0, input_int;
  8.  
  9.     char *FileNameSTR[20];
  10.     FILE *fileP; 
  11. .
  12. .
  13. .
  14.  
  15. // Option 2  'File I/O'
  16.          else if(opt==2) {
  17.  
  18.                   // Read from file          
  19.                   printf("Enter a file name to read: ");
  20.                   gets(*FileNameSTR);      
  21.  
  22.                   if((fileP=fopen("FileNameSTR","r"))==NULL)
  23.                        printf("\n> Specified file not found!\n\n");
  24.  
  25.                   else {
  26.                        printf("Integers in file:\n");
  27.                        for(L=1;L<=SIZE;L++) 
  28.                               fscanf(*FileNameSTR,"%d",&NumARR[L]);
  29.  
  30.  
  31.                        while(!feof(FileNameSTR[20])) {
  32.                               for(L=1;L<=SIZE;L++) { printf("%d\n",NumARR[L]); }                 
  33.                                                  }
  34.                        fclose(FileNameSTR);
  35.                        printf("\n> Reading process done.\n\n");
  36.                        } // end of else
  37.  
  38.  
  39.                   // Write to file     
  40.                   printf("Enter a file name to read: ");
  41.                   gets(*FileNameSTR);        
  42.  
  43.                   if((fileP=fopen("FileNameSTR","w"))==NULL)
  44.                        printf("\n> Specified file not found!\n\n");     
  45.  
  46.                   else {
  47.                        for(L=1;L<=SIZE;L++) {
  48.                              printf("Int #%d: ",L); 
  49.                              scanf("%d",&NumARR[L]);  
  50.                                            }
  51.  
  52.                        while(!feof(stdin)) {
  53.                               for(L=1;L<=SIZE;L++) { fprintf(FileNameSTR,"%d\n",NumARR[L]); }            
  54.                                            }                    
  55.                        fclose(FileNameSTR);
  56.                        printf("\n> Reading process done.\n\n");              
  57.                        } // end of else
  58.  
  59.                     } // end of if(2)
  60.  
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..
Feb 21 '07 #1
2 1682
willakawill
1,646 1GB
Hi. It may work better if you declare your file string like this:
Expand|Select|Wrap|Line Numbers
  1. char FileNameSTR[50];
Then use it like this:
Expand|Select|Wrap|Line Numbers
  1. gets(FileNameSTR);  
and this:
Expand|Select|Wrap|Line Numbers
  1. fscanf(FileNameSTR,"%d",&NumARR[L]);
Feb 21 '07 #2
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"



Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. #define SIZE 10 
  4. .
  5. .
  6. .
  7.     int opt, NumARR[SIZE], L, MaxINT, sum=0, input_int;
  8.  
  9.     char FileNameSTR[20];
  10.     FILE *fileP; 
  11. .
  12. .
  13. .
  14.          // Option 2  'File I/O'
  15.          else if(opt==2) {
  16.  
  17.                   // Read from file          
  18.                   printf("Enter a file name to read: ");
  19.                   fflush(stdin);  // skip gets() without flush
  20.                   gets(FileNameSTR);      
  21.  
  22.                   if((fileP=fopen(FileNameSTR,"r"))==NULL)
  23.                        printf("\n> Specified file not found!\n\n");
  24.  
  25.                   else {
  26.                        printf("Integers in file:\n");
  27.                        for(L=1;L<=SIZE;L++) 
  28.                               fscanf(fileP,"%d",&NumARR[L]);
  29.  
  30.  
  31.                        while(!feof(fileP)) {
  32.                               for(L=1;L<=SIZE;L++) { printf("%d\n",NumARR[L]); }                 
  33.                                                  }
  34.                        fclose(fileP);
  35.                        printf("\n> Reading process done.\n\n");
  36.                        } // end of else
  37.  
  38.  
  39.                   // Write to file     
  40.                   printf("Enter a file name to read: ");
  41.                   gets(FileNameSTR);          
  42.  
  43.                   if((fileP=fopen(FileNameSTR,"w"))==NULL)
  44.                        printf("\n> Specified file not found!\n\n");     
  45.  
  46.                   else {
  47.                        for(L=1;L<=SIZE;L++) {
  48.                              printf("Int #%d: ",L); 
  49.                              scanf("%d",&NumARR[L]);  
  50.                                            }
  51.  
  52.                        while(!feof(stdin)) {
  53.                               for(L=1;L<=SIZE;L++) { fprintf(fileP,"%d\n",NumARR[L]); }            
  54.                                            }                    
  55.                        fclose(fileP);
  56.                        printf("\n> Reading process done.\n\n");              
  57.                        } // end of else
  58.  
  59.                     } // end of if(2)
  60.  
i think i can handle with this; but any better solutions and suggestions will be appreciated, thanks again.
Feb 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
3
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...
4
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...
3
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...
2
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...
4
cassbiz
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...
4
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.