#include "stdafx.h"
#include "string.h"
#include "stdio.h"
void CharReadWrite(FILE *fin);
FILE *fptr2;
int _tmain(int argc, _TCHAR* argv[])
{
char filename[]="ReadMe.txt";
if (fopen_s( &fptr2, filename, "r" ) != 0 )
...
|
I had just a look at the stdio.h where I could find the FILE structure
definition:
typedef struct {
int ...
|
Assume I have a file pointer FILE* myfile. Is there a way to retrieve the name of the file where myfile is reading from or writing to?
|
in the following code when ran will produce a Segmentation Fault, due to a FILE* being passed to fclose which contains no address (NULL).
I'm wondering why this is happening, the FILE* ... |
Just a quick question: Is there a way to duplicate a file pointer (those returned by fopen()), similar to how dup() duplicates a file handlers returned by functions like open()?
Basically, I ... |
A simple question:
How do I check the access mode of an already opened file pointer?
So say a function is passed an already opened FILE pointer:
//Pseudo code
...
|
For example, if I have
FILE *fp, *tfp;
fp = fopen (file, mode);
tfp = fp;
is this possible?
|
|
This is a very small portion of a large project...
These are typedefs defined in standard header file for the project.
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint8_t u_int8_t;
Now this is the actual ... |
I got a descriptor for a TCP socket in the following manner :
int desc = accept(socket_descriptor, &client_address, &len)
Now from this descriptor desc I want to get a file pointer. ... |
|
|
|
Hi everyone! I am currently experiencing some problems... My program crashes when i open a file which does exist. The problem seems to happen when two pointers point at the same file. Could it be the reason why my program's crashing? Paul. Thanks a lot. Hi,. Is the program crashing during opening the file or during any file operations when u ... |
|
|
Hi, I've been staring myself blind on the same little code now and I cant see the problem. The filepointer seems to not change when I open it in a function. I've written like this (a bit pseudo here): void func(FILE* file) { /* print addr of file (2)*/ file = fopen("thefile", "wb"); /* open as binary */ /* print addr ... |
|
I have made a simple program to read the contents of a file.The FILE pointer returns NULL at the very beginning eventhough the file is present.Now if I modify my program and use command line arguments instead, I get the desired output.Now after I have run this program with argv; and I shift back to the one without command line arguments ... |
I am writing a code that should do the following.. Count how many times a certain string occurs in the second column of a file for a range in the first column.. This is a simple version of my code :- Code: #include int main() { FILE *fptr1; int c[30]; int n; for(n = 0; n<=30;n++) {c[n]=0;} int x=0; int i=0; ... |
20. File Pointers cboard.cprogramming.com |
Hi all, I am relatively new at programming in C so forgive me if this question sound a bit idiotic. I have a problem regarding passing file pointers in a program I am writing. So my input is in the following format from a file: Code: 0 3 1 0 2 0 3 0 4 1 2 1 3 1 4 ... |
I'm having trouble understanding this function, I know it reads a line and copies it to a string, but I don't know what arguments to use when calling it. I haven't met the file pointer before and don't quite know how it works. I'm guessing it needs to point to the string which is being read, but I want to read ... |
23. file pointer cboard.cprogramming.com |
#include #include #include int main() { FILE *fp1,*fpo; char s[20][100],ch; int i,j; fp1=fopen("pr31.c","w"); if(fp1==NULL) { printf("cannot open file"); } while(strlen(gets(s))>0) { fputs(s,fp1); fputs("\n",fp1); } printf("file closed\n\n"); fpo=fopen("pr32.c","w"); ch=fgetc(fp1); i=j=0; while(!feof(fp1)) { if(ch=='\n') { s[i][j]='\0'; i++; j=0; } else { s[i][j]=ch; j++; } ch=fgetc(fp1); } for(j=0;j |
|
|
Code: ==32022== Invalid read of size 4 ==32022== at 0x40B11AD: (within /lib/tls/i686/cmov/libc-2.8.90.so) ==32022== by 0x40B1E7F: (within /lib/tls/i686/cmov/libc-2.8.90.so) ==32022== by 0x4072DE9: exit (in /lib/tls/i686/cmov/libc-2.8.90.so) ==32022== by 0x405A68C: (below main) (in /lib/tls/i686/cmov/libc-2.8.90.so) ==32022== Address 0x41a49f8 is 104 bytes inside a block of size 352 free'd ==32022== at 0x4024E5A: free (vg_replace_malloc.c:323) ==32022== by 0x804A3F6: outline_free (outline.c:324) ==32022== by 0x8049369: main (main.c:234) ==32022== Invalid read ... |
#include #include main (int argc, char *argv[]) { FILE *out0,*out1,*out2,*out3,*out4; double alfa,omega,k0,c; char filtemp [128]; sprintf(filtemp,"a%3.1lfW%3.1lfk%3.1lfBA%3.1lfsignature.dat",alfa,omega,k0,c); if(!(out0=fopen(filtemp,"w"))) { printf("Can't open %s file!",filtemp); exit(0); } sprintf(filtemp,"a%3.1lfW%3.1lfk%3.1lfBA%3.1lfpotential.dat",alfa,omega,k0,c); if(!(out1=fopen(filtemp,"w"))) { printf("Can't open %s file!",filtemp); exit(0); } sprintf(filtemp,"a%3.1lfW%3.1lfk%3.1lfBA%3.1lfderivative.dat",alfa,omega,k0,c); if(!(out2=fopen(filtemp,"w"))) { printf("Can't open %s file!",filtemp); exit(0); } sprintf(filtemp,"a%3.1lfW%3.1lfk%3.1lfBA%3.1lfresults.dat",alfa,omega,k0,c); if(!(out3=fopen(filtemp,"w"))) { printf("Can't open %s file!",filtemp); exit(0); } fprintf(out0,"test"); fprintf(out1,"test"); fprintf(out2,"test"); fprintf(out3,"test"); fclose(out0); fclose(out1); fclose(out2); fclose(out3); ... |
|
|
teyla:~ quasigreat$ cat carpool.txt 4 75 11.0 2 50 9.0 5 95 15.5 2 60 4.5 4 35 4.3 6 70 20.7 0 0 0 teyla:~ quasigreat$ ~quasigreat/a.out Please enter the minimum efficiency> 25 teyla:~ quasigreat$ cat effic.txt CARPOOLS MEETING MINIMUM PASSENGER EFFICIENCY OF 25 PASSENGER KM / L Passengers Weekly Commute Gasoline Efficiency Weekly (km) Consumption(L) (pass km / L) ... |
I have the code below to open a file, append some text and then display the contents of that file on the screen. I am new to programming and trying to learn on my own for the company I work for. Any help is greatly appreciated. I was expecting to have this statement - if (fptr == NULL); be false but ... |
/* * remove the extra & at fp * * fileScan does return any value therefore while can't work checking if it is the EOF * population, squareMilege, pollution, crime, expense, highways are not the same that in the function; * those are a copy */ while(fileScan(fp, cityName, population, squareMileage, pollution, crime, expense, highways) != EOF) // get next char from ... |
FILE objects are usually created by a call to either fopen or tmpfile, which both return a reference to one of these objects. The content of a FILE object is not meant to be read from outside the functions of the cstdio library; In fact, its main purpose is to be referenced as an argument in all stream-involving functions of this ... |
#include int main ( void ) { char str [ 80 ]; FILE * input, * east; if ( ( input = fopen ( "east", "r" ) ) == NULL ) { printf ( "Cannot open file\n" ); exit ( 1 ); } printf ("Enter in the firstname, lastname teamname"); printf (", jersey number, points and game in that order"); ... |
#include #include int main(void) { FILE *sfp; unsigned int score; sfp = fopen("C:\\scores.txt","r"); if ( sfp != (FILE *) NULL ) { /* Put a loop around this bit */ fscanf(sfp, "%u", &score); printf("score %u\n",score); /* end of loop */ fclose(sfp); } else { /* find out what the error is ! */ printf("open failed with errno=%d\n", errno); } ... |
long time; /* know C? */ Unprecedented performance: Nothing ever ran this slow before. Any sufficiently advanced bug is indistinguishable from a feature. Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31. The best way to accelerate an IBM is at 9.8 m/s/s. recursion (re - cur' - zhun) n. 1. (see recursion) |
|
|
|
|
FILE *readfile; int lexInit(char* filename) { readfile = fopen(filename,"r"); if(readfile == 0) { printf("\nfile could not be opened\n\n"); } else { printf("\n File opened\n"); } return 0; } int lex(Lexeme *lexeme_pointer) { char ch; ch = readchar(); lexeme_pointer->type = 'funny'; printf("type = %s",&lexeme_pointer.type); return 0; } ///readchar int readchar() { char ch; ch = fgetc(readfile); return ch; } int pushback() { ... |
|
|
Hi every one, I am trying to write a function that deletes a whitespace that seperates the last name followed by a ',' from the first name Initial. It is part of a compression program that we have to write. I am having trouble understanding pointers. So if anyone could help me, that would be great. Here the function I have ... |
I am trying to open a file and save the a pointer to that file in *out_fp Keep getting a syntax error at around this point in my code, know it is prob. easily fixed but just haven't been able to get it. I have also added the code before this part as it could be the problem also where i ... |
wazzup?...i got 4 functions including main (see below)...main gives the option of calling engine() or find()...these 2 call funk() for the computation and printinf of results...find() works fine when it call funk()...so funk() is working alright...engine() with funk() gives a Segmentation Fault core dumped!...engine() is this tinee tiny lil' function with 10 lines of code...can't seem to figure out whats' wrong...tried ... |
Shadow, you've lost me ! Are we talking about the same thing?!! Read the original post.... it is a request for a function to obtain the name of the file opened by any given file pointer. So, if we did this in main(): >FILE *fp = fopen ("test.txt", "r"); Then passed fp to another function like this: >myfunc(fp); How would myfunc ... |
My program is to get 5 fields, including one called 'position' that shows the sequential position of the record in the file. If I have 5 records in the file, *.txt, the last position in that file should be 4. If i want to put a new record in it should be position 5. After I use f_open to open the ... |
|
|
52. file pointer cboard.cprogramming.comIf you had 2 integer's (int a and int b) to copy the contents from one integer to another you'd do - a = b; If you have two pointers(int* a and int* b) to copy the contents from one to the other you'd do - a = b; If this was a pointer to a pointer then the statement would ... |
53. FILE pointers cboard.cprogramming.com |
Hi, I'm new to C and after 4 hours, I can't figure out how to parse this file. The ugly code: Code: // Scan input data while (fscanf(inputFile, "%i %s %i %i\n", &data.week, &data.name, &data.units, &data.price) != EOF) { if (data.week == 0) { totalWeek0 += data.price; } if (data.week == 1) { totalWeek1 += data.price; } if (data.week == 2) ... |
|
i still think you don't need a pointer to pointer, a pointer itself should do it because at some points you say &fp, you send the address of your pointer.. which doesn't really make sence because you give him the address of the address that you need.. you can just give him the address that he needs by sending fp |
|
I want to establish connection with oscilloscope via rs232. How could i do it with FILE pointer? I`m using BorlandC 3.1 File is defined as a structure in : typedef struct{ short level; unsigned flags; char fd; unsigned char hold; short bsize; unsigned char *buffer, *curp; unsigned istemp; short token; } FILE; } Thanks, Ginrare. |
#include #include #include #include void makeUpper (char *s); void menu (void); int numberGenerator(int min, int max); char characterGenerator(void); main() { int i = 0, i2 = 0, j = 0, wordcount = 0, cancel = 0, run = 1, posx = 0, posy = 0, pass = 0, direction = 0; char temp[50], words[10][16], puzzle[25][70], condition; do ... |
|
#include #include #include #include #include #include #include #include #include #include int main() { FILE *logs; logs = fopen("/home/aniroot/logs/log.txt","a"); if(logs = NULL) { printf("fopen failed ... There would be no log for this session!!!"); } int sockfd,newfd; int err; struct addrinfo *res,*p,hints; struct sockaddr_storage their_addr; socklen_t addr_size; int yes=1; char ip[INET6_ADDRSTRLEN]; memset(&hints,0,sizeof(hints)); hints.ai_family=AF_UNSPEC; hints.ai_flags=AI_PASSIVE; hints.ai_socktype=SOCK_STREAM; printf("Server is open for listening on port ... |
|
#include #include int main(int argc, char *argv[]) { char file_name[100]; /*declare char arrays to hold file name and text*/ char file_text[500]; char c; /*char to hold text characters */ int counter1, counter2; FILE *input_file, *input1_file, *output_file; /*declaration of file pointers */ printf("\nenter the name & extension of text file to create:"); scanf("%s", &file_name); printf("\nenter the text to be reversed:"); ... |
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "estructuras.h" #include "funciones.h" #include "menus.h" #define num 999 /* Localizado en menus.h */ void menuprincipal(cli *); //void menucliente(cli *); //void menuproductos(); //void ... |
#include #include int main() { FILE **fp; char filename[20]; int i; fp = malloc( sizeof(FILE *) * 10); if( fp != NULL ) { for(i=0; i<10; i++) { sprintf(filename, "%s%d.txt", "file",i+1); if( ( fp[i] = fopen(filename, "a+") ) == NULL ) { printf("Error: File \"%s\" cannot be opened\n", filename); continue; } fprintf( fp[i], "%s", "Hello There"); fclose(fp[i]); } } ... |
|
I am using filepointer in C. when I compile the code and run it for the first time the filepointer works fine and logs are written into log files. But during next hits there is an inconsistency in logs getting written. sometimes getting written and someother times not written. But during all those times the file pointer returns a valid integer. ... |
/* 1. Get array dimensions and print array. 2. Create array based on total. 3. Fill AND sort array. 4. Print sorted array. */ #include #include #define FILENAME "data.txt" #define MODE "r" int get_dim(FILE *); int *make_array(int ); void fill_array(FILE *, int *, int ); void insertion(int *, int ); int main(void) { FILE *fp = fopen(FILENAME, MODE); int ... |
|
Thanks a lot for digging that up! I think that explains the problem allthough i have to admit i didn't get this in detail. So does this mean i'll have to manage the file positions myself ( e.g. with temporary variables) lets say for the simple task of reading a value from a file just written to it? |
I asked an almost identical question in the tek-tips pascal forum. The general opinion seemed to be that this (allocating a file to two file structure variables) was unnecessary and probably undesirable; how it behaves might even vary with how the operating system handles files (for instance file-control-block or file-handle approaches may vary in how they behave)Of course, that was Pascal, ... |
Howdy,Thanks for helping a new programmer, I sincerely appreciate it. I am trying to copy character string information stored in a file pointer to another pointer.Should I initialize the pointer likechar newPtr[90000]? (yea the file pointer being copied to it is big!)And what statement do I use to transfer data from the two pointers?*newPtr = *inputPtr; ?Note: ... |