473,387 Members | 1,512 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.

Help with File pointers in C

Say I have the following code:

Expand|Select|Wrap|Line Numbers
  1.  #include<stdio.h> 
  2. #include<stdlib.h>
  3.  
  4. void fileOpener(FILE*);
  5.  
  6. int main(void)
  7. {
  8. FILE *fpFile;
  9. char test[14];
  10.  
  11. fileOpener(fpFile);
  12.  
  13. fgets(test, sizeof(test), fpFile);
  14.  
  15. return(0);
  16. }
  17.  
  18.  
  19. void fileOpener(FILE *fpntr)
  20. {
  21. fpntr = fopen("inst.dat", "r");
  22. }
  23.  
  24.  
What I'm trying to do is be able to open the stream in fileOpener and then be able to make manipulations back up in main or pass the address of the pointer on to subsequent functions. When I try to compile the code I get a Segmentation Fault. Could someone help me out??? I'd greatly appreciate it.
Nov 25 '05 #1
2 3514
Niheel
2,460 Expert Mod 2GB
Anyone with C experience that can help whiteCoding out?
Nov 29 '05 #2
yeo
1
try passing by value instead of address, since the pointer itself already represents a memory location, passing the "address of an address" does not make sense. So it would be:

Expand|Select|Wrap|Line Numbers
  1. int fileOpener(FILE*);
  2.  
  3. int main(void)
  4. {
  5. FILE *fpFile;
  6. char test[14];
  7.  
  8. fpFile = fileOpener(fpFile);
  9.  
  10. fgets(test, sizeof(test), fpFile);
  11.  
  12. return(0);
  13. }
  14.  
  15.  
  16. int fileOpener(FILE *fpntr)
  17. {
  18. fpntr = fopen("inst.dat", "r");
  19.  
  20. return fptr;
  21. }
Mar 26 '07 #3

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

Similar topics

4
by: Greg Baker | last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to post code and ask for help? I hope so.. :) Here's my problem: I am trying problem 127 of the valladolid online...
5
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
1
by: David Goodyear | last post by:
At the moment im experimenting with ideas in C++ and would really like to solve the following, please please help. Sorry i dont even know what the subject is this would come under? :( Sorry if...
5
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file and copies the contents into the two char*s. Now...
1
by: Geoff | last post by:
I was wondering if anyone could help me with a problem I am having. I am trying to read in a list of numbers from a file and then sort them using pointers and malloc() and free(). I know how to...
2
by: leo2100 | last post by:
Hi, I need help with this program. The program is supposed to take a text file and identify the words in it, then it should print them and count how many times a word is repeated. At first main...
9
by: Dadio | last post by:
Hi! I have to take some strings from a file and put them in a record... The various strings in the file are written on this way: string1|string2|string3|string4|string5| This is the program...
4
memoman
by: memoman | last post by:
Can any body help me in that program ??? mail me if anybody could reach any -helpfull- thing Write a C++ program that namely insert, delete, and search in a fixed record length file (containing...
8
by: isaac2004 | last post by:
hello, i posted with a topic like this but got no real feedback(prob cuz of lapse in my explanation) so i am trying it again. i am trying to set up a function that brings in a txt file and adds the...
4
by: jjh5030 | last post by:
This is a programming assignment. You are asked to work with pointers. Be aware that error messages are often not very helpful when your pointers point to bad locations. Therefore, reserve...
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...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.