Search Results

Search found 54 results on 3 pages for 'fseek'.

Page 1/3 | 1 2 3  | Next Page >

  • How is fseek() implemented in the filesystem?

    - by pajton
    This is not a pure programming question, however it impacts the performance of programs using fseek(), hence it is important to know how it works. A little disclaimer so that it doesn't get closed. I am wondering how efficient it is to insert data in the middle of the file. Supposing I have a file with 1MB data and then I insert something at the 512KB offset. How efficient would that be compared to appending my data at the end of the file? Just to make the example complete lets say I want to insert 16KB of data. I understand the answer varies depending on the filesystem, however I assume that the techniques used in common filesystems are quite similar and I just want to get the right notion of it.

    Read the article

  • Fseek on C problem

    - by Pedro
    i'm testing this code, but doesn't work, it always says that an error occurred :S int main(int argc, char **argv) { FILE *file_pointer; file_pointer = fopen("text.txt","r"); if(fseek(file_pointer, 0, -1)) { puts("An error occurred"); } else { char buffer[100]; fgets(buffer, 100, file_pointer); puts("The first line of the file is:"); puts(buffer); } fclose(file_pointer); return 0; }

    Read the article

  • C : files manipulation Can't figure out how to simplify this code with files manipulation.

    - by Bon_chan
    Hey guys, I have been working on this code but I can't find out what is wrong. This program does compile and run but it ends up having a fatal error. I have a file called myFile.txt, with the following content : James------ 07.50 Anthony--- 17.00 And here is the code : int main() { int n =2, valueTest=0,count=0; FILE* file = NULL; float temp= 00.00f, average= 00.00f, flTen = 10.00f; float *totalNote = (float*)malloc(n*sizeof(float)); int position = 0; char selectionNote[5+1], nameBuffer[10+1], noteBuffer[5+1]; file = fopen("c:\\myFile.txt","r"); fseek(file,10,SEEK_SET); while(valueTest<2) { fscanf(file,"%5s",&selectionNote); temp = atof(selectionNote); totalNote[position]= temp; position++; valeurTest++; } for(int counter=0;counter<2;counter++) { average += totalNote[counter]; } printf("The total is : %f \n",average); rewind(file); printf("here is the one with less than 10.00 :\n"); while(count<2) { fscanf(file,"%10s",&nameBuffer); fseek(file,10,SEEK_SET); fscanf(file,"%5s",&noteBuffer); temp = atof(noteBuffer); if(temp<flTen) { printf("%s who has %f\n",nameBuffer,temp); } fseek(file,1,SEEK_SET); count++; } fclose(file); } I am pretty new to c and find it more difficult than c# or java. And I woud like to get some suggestions to help me to get better. I think this code could be simplier. Do you think the same ?

    Read the article

  • How to move file pointer to a particular location using fseek()?

    - by Noge
    My intention is to read every elements in the 2nd column into a buffer[] from the following .txt file: 9992891234 09.920 15.771 11.909 9992345971 07.892 12.234 09.234 9992348971 64.567 70.456 50.987 9992348231 89.234 85.890 58.982 I have know of a way to do it by using fscanf(): for (int i=0;i<4;i++) { fscanf(pFile, "%lld", &junk); fscanf(pFile, "%f", &buffer[i]); fscanf(pFile, "%f", &junk); fscanf(pFile, "%f", &junk); } However, since I'm doing parallel programing which requires me to use different Windows Threads to read different columns, so I'll need to read the elements in the 2nd column directly using fseek(). The question here is, what should I put in the 2nd argument in fseek() in the code below to move my file pointer to read the 2nd element of the 2nd line? fscanf(pFile, "%llf", &junk);//<------this is used to skip the 1st data for (int i=0;i<4;i++) { fscanf(pFile, "%f", &buffer[i]); fseek ( pFile , ??, SEEK_CUR );//<----how do I calculate this offset? }

    Read the article

  • Why does this code read all ' ' for the anything after the 4th character?

    - by djs22
    #define fileSize 100000 int main(int argc, char *argv[]){ char *name=argv[1]; char ret[fileSize]; FILE *fl = fopen(name, "rb"); fseek(fl, 0, SEEK_END); long len = fileSize; fseek(fl, 0, SEEK_SET); //fread(ret, 1, len, fl); int i; *(ret+fileSize) = '\0'; for (i=0; i<fileSize; i++){ *(ret+i)=fgetc(fl); printf("byte : %s \n", ret); } fclose(fl); } In the above code, when I feed the name of a jpeg file, it reads anything after the 4th character as ' '...any ideas? Thanks!

    Read the article

  • Function From C to Delphi

    - by XBasic3000
    I created a function similar below in delphi code. but it wont work. What is the proper way to convert this? char* ReadSpeechFile(char* pFileName, int *nFileSize) { char *szBuf, *pLinearPCM; int nSize; FILE* fp; //read wave data fp = fopen(pFileName, "rb"); if(fp == NULL) return NULL; fseek(fp, 0, SEEK_END); nSize = ftell(fp); //linear szBuf = (char *)calloc(nSize, sizeof(char)); fseek(fp, 0, SEEK_SET); fread(szBuf, sizeof(char), nSize, fp); fclose(fp); *nFileSize = nSize; return szBuf; }

    Read the article

  • Unknown symbols when I read file

    - by Sergey Gavruk
    I read file, but in the end of file i get unknown symbols: int main() { char *buffer, ch; int i = 0, size; FILE *fp = fopen("file.txt", "r"); if(!fp){ printf("File not found!\n"); exit(1); } fseek(fp, 0, SEEK_END); size = ftell(fp); printf("%d\n", size); fseek(fp, 0, SEEK_SET); buffer = malloc(size * sizeof(*buffer)); while(((ch = fgetc(fp)) != NULL) && (i <= size)){ buffer[i++] = ch; } printf(buffer); fclose(fp); free(buffer); getch(); return 0; }

    Read the article

  • Suggestions for duplicate file finder algorithm (using C)

    - by Andrei Ciobanu
    Hello, I wanted to write a program that test if two files are duplicates (have exactly the same content). First I test if the files have the same sizes, and if they have i start to compare their contents. My first idea, was to "split" the files into fixed size blocks, then start a thread for every block, fseek to startup character of every block and continue the comparisons in parallel. When a comparison from a thread fails, the other working threads are canceled, and the program exits out of the thread spawning loop. The code looks like this: dupf.h #ifndef __NM__DUPF__H__ #define __NM__DUPF__H__ #define NUM_THREADS 15 #define BLOCK_SIZE 8192 /* Thread argument structure */ struct thread_arg_s { const char *name_f1; /* First file name */ const char *name_f2; /* Second file name */ int cursor; /* Where to seek in the file */ }; typedef struct thread_arg_s thread_arg; /** * 'arg' is of type thread_arg. * Checks if the specified file blocks are * duplicates. */ void *check_block_dup(void *arg); /** * Checks if two files are duplicates */ int check_dup(const char *name_f1, const char *name_f2); /** * Returns a valid pointer to a file. * If the file (given by the path/name 'fname') cannot be opened * in 'mode', the program is interrupted an error message is shown. **/ FILE *safe_fopen(const char *name, const char *mode); #endif dupf.c #include <errno.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include "dupf.h" FILE *safe_fopen(const char *fname, const char *mode) { FILE *f = NULL; f = fopen(fname, mode); if (f == NULL) { char emsg[255]; sprintf(emsg, "FOPEN() %s\t", fname); perror(emsg); exit(-1); } return (f); } void *check_block_dup(void *arg) { const char *name_f1 = NULL, *name_f2 = NULL; /* File names */ FILE *f1 = NULL, *f2 = NULL; /* Streams */ int cursor = 0; /* Reading cursor */ char buff_f1[BLOCK_SIZE], buff_f2[BLOCK_SIZE]; /* Character buffers */ int rchars_1, rchars_2; /* Readed characters */ /* Initializing variables from 'arg' */ name_f1 = ((thread_arg*)arg)->name_f1; name_f2 = ((thread_arg*)arg)->name_f2; cursor = ((thread_arg*)arg)->cursor; /* Opening files */ f1 = safe_fopen(name_f1, "r"); f2 = safe_fopen(name_f2, "r"); /* Setup cursor in files */ fseek(f1, cursor, SEEK_SET); fseek(f2, cursor, SEEK_SET); /* Initialize buffers */ rchars_1 = fread(buff_f1, 1, BLOCK_SIZE, f1); rchars_2 = fread(buff_f2, 1, BLOCK_SIZE, f2); if (rchars_1 != rchars_2) { /* fread failed to read the same portion. * program cannot continue */ perror("ERROR WHEN READING BLOCK"); exit(-1); } while (rchars_1-->0) { if (buff_f1[rchars_1] != buff_f2[rchars_1]) { /* Different characters */ fclose(f1); fclose(f2); pthread_exit("notdup"); } } /* Close streams */ fclose(f1); fclose(f2); pthread_exit("dup"); } int check_dup(const char *name_f1, const char *name_f2) { int num_blocks = 0; /* Number of 'blocks' to check */ int num_tsp = 0; /* Number of threads spawns */ int tsp_iter = 0; /* Iterator for threads spawns */ pthread_t *tsp_threads = NULL; thread_arg *tsp_threads_args = NULL; int tsp_threads_iter = 0; int thread_c_res = 0; /* Thread creation result */ int thread_j_res = 0; /* Thread join res */ int loop_res = 0; /* Function result */ int cursor; struct stat buf_f1; struct stat buf_f2; if (name_f1 == NULL || name_f2 == NULL) { /* Invalid input parameters */ perror("INVALID FNAMES\t"); return (-1); } if (stat(name_f1, &buf_f1) != 0 || stat(name_f2, &buf_f2) != 0) { /* Stat fails */ char emsg[255]; sprintf(emsg, "STAT() ERROR: %s %s\t", name_f1, name_f2); perror(emsg); return (-1); } if (buf_f1.st_size != buf_f2.st_size) { /* File have different sizes */ return (1); } /* Files have the same size, function exec. is continued */ num_blocks = (buf_f1.st_size / BLOCK_SIZE) + 1; num_tsp = (num_blocks / NUM_THREADS) + 1; cursor = 0; for (tsp_iter = 0; tsp_iter < num_tsp; tsp_iter++) { loop_res = 0; /* Create threads array for this spawn */ tsp_threads = malloc(NUM_THREADS * sizeof(*tsp_threads)); if (tsp_threads == NULL) { perror("TSP_THREADS ALLOC FAILURE\t"); return (-1); } /* Create arguments for every thread in the current spawn */ tsp_threads_args = malloc(NUM_THREADS * sizeof(*tsp_threads_args)); if (tsp_threads_args == NULL) { perror("TSP THREADS ARGS ALLOCA FAILURE\t"); return (-1); } /* Initialize arguments and create threads */ for (tsp_threads_iter = 0; tsp_threads_iter < NUM_THREADS; tsp_threads_iter++) { if (cursor >= buf_f1.st_size) { break; } tsp_threads_args[tsp_threads_iter].name_f1 = name_f1; tsp_threads_args[tsp_threads_iter].name_f2 = name_f2; tsp_threads_args[tsp_threads_iter].cursor = cursor; thread_c_res = pthread_create( &tsp_threads[tsp_threads_iter], NULL, check_block_dup, (void*)&tsp_threads_args[tsp_threads_iter]); if (thread_c_res != 0) { perror("THREAD CREATION FAILURE"); return (-1); } cursor+=BLOCK_SIZE; } /* Join last threads and get their status */ while (tsp_threads_iter-->0) { void *thread_res = NULL; thread_j_res = pthread_join(tsp_threads[tsp_threads_iter], &thread_res); if (thread_j_res != 0) { perror("THREAD JOIN FAILURE"); return (-1); } if (strcmp((char*)thread_res, "notdup")==0) { loop_res++; /* Closing other threads and exiting by condition * from loop. */ while (tsp_threads_iter-->0) { pthread_cancel(tsp_threads[tsp_threads_iter]); } } } free(tsp_threads); free(tsp_threads_args); if (loop_res > 0) { break; } } return (loop_res > 0) ? 1 : 0; } The function works fine (at least for what I've tested). Still, some guys from #C (freenode) suggested that the solution is overly complicated, and it may perform poorly because of parallel reading on hddisk. What I want to know: Is the threaded approach flawed by default ? Is fseek() so slow ? Is there a way to somehow map the files to memory and then compare them ?

    Read the article

  • C file read leaves garbage characters

    - by KJ
    Hi. I'm trying to read the contents of a file into my program but I keep occasionally getting garbage characters at the end of the buffers. I haven't been using C a lot (rather I've been using C++) but I assume it has something to do with streams. I don't really know what to do though. I'm using MinGW. Here is the code (this gives me garbage at the end of the second read): include include char* filetobuf(char *file) { FILE *fptr; long length; char *buf; fptr = fopen(file, "r"); /* Open file for reading */ if (!fptr) /* Return NULL on failure */ return NULL; fseek(fptr, 0, SEEK_END); /* Seek to the end of the file */ length = ftell(fptr); /* Find out how many bytes into the file we are */ buf = (char*)malloc(length+1); /* Allocate a buffer for the entire length of the file and a null terminator */ fseek(fptr, 0, SEEK_SET); /* Go back to the beginning of the file */ fread(buf, length, 1, fptr); /* Read the contents of the file in to the buffer */ fclose(fptr); /* Close the file */ buf[length] = 0; /* Null terminator */ return buf; /* Return the buffer */ } int main() { char* vs; char* fs; vs = filetobuf("testshader.vs"); fs = filetobuf("testshader.fs"); printf("%s\n\n\n%s", vs, fs); free(vs); free(fs); return 0; } The filetobuf function is from this example http://www.opengl.org/wiki/Tutorial2:_VAOs,_VBOs,_Vertex_and_Fragment_Shaders_%28C_/_SDL%29. It seems right to me though. So anyway, what's up with that?

    Read the article

  • Loading machinecode from file into memory and executing in C -- mprotect failing

    - by chartreusekitsune
    Hi I'm trying to load raw machine code into memory and run it from within a C program, right now when the program executes it breaks when trying to run mprotect on the memory to make it executable. I'm also not entirely sure that if the memory does get set right it will execute. What I currently have is the following: #include <memory.h> #include <sys/mman.h> #include <stdio.h> int main ( int argc, char **argv ) { FILE *fp; int sz = 0; char *membuf; int output = 0; fp = fopen(argv[1],"rb"); if(fp == NULL) { printf("Failed to open file, aborting!\n"); exit(1); } fseek(fp, 0L, SEEK_END); sz = ftell(fp); fseek(fp, 0L, SEEK_SET); membuf = (char *)malloc(sz*sizeof(char)); if(membuf == NULL) { printf("Failed to allocate memory, aborting!\n"); exit(1); } memset(membuf, 0x90, sz*sizeof(char)); if( mprotect(membuf, sz*sizeof(char), PROT_EXEC | PROT_READ | PROT_WRITE) == -1) { printf("mprotect failed!!! aborting!\n"); exit(1); } if((sz*sizeof(char)) != fread(membuf, sz*sizeof(char), 1, fp)) { printf("Read failed, aborting!\n"); exit(1); } __asm__ ( "call %%eax;" : "=a" (output) : "a" (membuf) ); printf("Output = %x\n", output); return 0; }

    Read the article

  • speed string search in PHP

    - by Marc
    Hi! I have a 1.2GB file that contains a one line string. What I need is to search the entire file to find the position of an another string (currently I have a list of strings to search). The way what I'm doing it now is opening the big file and move a pointer throught 4Kb blocks, then moving the pointer X positions back in the file and get 4Kb more. My problem is that a bigger string to search, a bigger time he take to got it. Can you give me some ideas to optimize the script to get better search times? this is my implementation: function busca($inici){ $limit = 4096; $big_one = fopen('big_one.txt','r'); $options = fopen('options.txt','r'); while(!feof($options)){ $search = trim(fgets($options)); $retro = strlen($search);//maybe setting this position absolute? (like 12 or 15) $punter = 0; while(!feof($big_one)){ $ara = fgets($big_one,$limit); $pos = strpos($ara,$search); $ok_pos = $pos + $punter; if($pos !== false){ echo "$pos - $punter - $search : $ok_pos <br>"; break; } $punter += $limit - $retro; fseek($big_one,$punter); } fseek($big_one,0); } } Thanks in advance!

    Read the article

  • php parsing csv with ftell

    - by Robert82
    I have a 500mb csv file with over 500,000 lines, each with 80 fields. I am using fget to process the file line by line. $col1 = array(); while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { $col1[] = $row[0]; } Because of an execution time limit on the PHP file by my hosting provider (120 seconds), I can't process the whole file in one run. I tried using ftell() and fseek() to remember the last position for restart. The trouble is, sometimes the ftell() position is in the middle of a row, and resuming means missing the first half of the row. Is there an elegant way to know the last line successfully processed, and resume from the one after it? I realize I can do a simple counter, and then loop through to that point again, but that would produce diminishing returns on the rows I can process towards the end of the file. Is there something like ftell() and fseek() that would work in my case? Or a way to limit ftell() to return the pointer for the end of the previous line?

    Read the article

  • Seeking past end of file causes Apache hang, and it never restarts.

    - by talkingnews
    I've actually solved my problem with a better script, but I'm still left wondering why Apache2 hung completely - this is an out-of-the-box ISPCONFIG 3.03 install, everything bang up to date, running perfectly. Until... The troublesome but innocent-looking script: $fp = fopen("/var/log/ispconfig/cron.log", "r"); fseek($fp, -5000, SEEK_END); $line_buffer = array(); while (!feof($fp)) { $line = fgets($fp, 1024); $line_buffer[] = $line; $line_buffer = array_slice($line_buffer, -10, 10); } foreach ($line_buffer as $line) { echo $line; } You get the idea, just a script I found on a forum somwehere. I did this for various logs, since it's a nice easy window on what's occurring (in a protect dir, of course!). One day, the logs having grown large an me having sorted all my cron, scripting and mail queue errors, I thought I was time to start afresh. updated, rebooted, archived and deleted the logs. When I ran my script a couple of hours later, it hung. And hung. 8 minutes I waited. Chrome timed the page out, of course, but the server never came back to life. htop showed /usr/sbin/apache2 -k restart using 100% CPU. Never came back until I did a service apache2 restart. Ran fine, as soon as I hit that logfile again...dead. So, I worked out it was the logfile script, and I worked out that seeking beyond the end of the file wasn't good, and I found a better script http://www.php.net/manual/en/function.fseek.php#90450 But what I'm left wondering is... why didn't something restart or kill the process? How was one hanging page able to bring down the whole server? It's running suphp. I say "out of the box", I've tweaked mysql and apache to fork and reserve sensible amounts of processes for the 512Mb RAM the VPS has, and it'll handle multiple refreshes of large pages, and hadn't hung before. Any ideas how I'd avoid this? Google isn't my friend in this instance beyond the reccs. above about number of processes vs RAM available.

    Read the article

  • Reading Binary file in C

    - by darkie15
    Hi All, I am having following issue with reading binary file in C. I have read the first 8 bytes of a binary file. Now I need to start reading from the 9th byte. Following is the code: fseek(inputFile, 2*sizeof(int), SEEK_SET); However, when I print the contents of the array where I store the retrieved values, it still shows me the first 8 bytes which is not what I need. Can anyone please help me out with this? Regards, darkie

    Read the article

  • Ajax to read updated values from XML

    - by punit
    I am creating file upload progress bar. I have a CGI script which copies the data, and here I increment the progress bar value by ONE after certain iterations. I am storing the incremented value in XML file (I also tried using plain text file). On the other side I have ajax reading incremented value from xml and depending on that it increments the DIV element. However, what happens here is, it seems to me that although the ajax reads all the incremented values but it processes it after the CGI has finished execution. That is progress bar starts execution once the file copying and other stuff in CGI is completed. My code is: AJAX:::: function polling_start() { //GETS CALLED WHEN USER HITS FILE UPLOAD BUTTON intervalID = window.setInterval(send_request,100); } window.onload = function (){ request = initXMLHttpClient(); request.overrideMimeType('text/xml'); progress = document.getElementById('progress'); } function initXMLHttpClient() { if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else{ // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp } function send_request() { request.open("GET","progress_bar.xml",true); request.onreadystatechange = request_handler; request.send(); } function request_handler() { if (request.readyState == 4 && request.status == 200) { var level=request.responseXML.getElementsByTagName('PROGRESS')[0].firstChild; progress.style.width = progress.innerHTML = level.nodeValue + '%'; progress.style.backgroundColor = "green"; } } /****ON SERVER SIDE*********/ char xmlDat1[] = "<DOCUMENT><PROGRESS>"; char xmlDat2[] = "</PROGRESS></DOCUMENT>"; fptr = fopen("progress_bar.xml", "w"); .........OTHER STUFF.............................. ................................. if(i == inc && j<=100) { fprintf(fptr, "%s\n", "\n\n\n]"); //fprintf(fptr, "%s\n", ""); fprintf(fptr, "%s", xmlDat1); // fprintf(fptr, "%d" ,j); fprintf(fptr, "%s" ,xmlDat2); fseek(fptr, 0, SEEK_SET); /*fprintf(fptr, "%d" ,j); fseek(fptr, 0, SEEK_SET);*/ i = 0; //sleep(1); j++; } (I also tried to write in .text, but same response) Any quick response would be appreciable.

    Read the article

  • Encode audio to aac with libavcodec

    - by ryan
    I'm using libavcodec (latest git as of 3/3/10) to encode raw pcm to aac (libfaac support enabled). I do this by calling avcodec_encode_audio repeatedly with codec_context-frame_size samples each time. The first four calls return successfully, but the fifth call never returns. When I use gdb to break, the stack is corrupt. If I use audacity to export the pcm data to a .wav file, then I can use command-line ffmpeg to convert to aac without any issues, so I'm sure it's something I'm doing wrong. I've written a small test program that duplicates my problem. It reads the test data from a file, which is available here: http://birdie.protoven.com/audio.pcm (~2 seconds of signed 16 bit LE pcm) I can make it all work if I use FAAC directly, but the code would be a little cleaner if I could just use libavcodec, as I'm also encoding video, and writing both to an mp4. ffmpeg version info: FFmpeg version git-c280040, Copyright (c) 2000-2010 the FFmpeg developers built on Mar 3 2010 15:40:46 with gcc 4.4.1 configuration: --enable-libfaac --enable-gpl --enable-nonfree --enable-version3 --enable-postproc --enable-pthreads --enable-debug=3 --enable-shared libavutil 50.10. 0 / 50.10. 0 libavcodec 52.55. 0 / 52.55. 0 libavformat 52.54. 0 / 52.54. 0 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0.10. 0 / 0.10. 0 libpostproc 51. 2. 0 / 51. 2. 0 Is there something I'm not setting, or setting incorrectly in my codec context, maybe? Any help is greatly appreciated! Here is my test code: #include <stdio.h> #include <libavcodec/avcodec.h> void EncodeTest(int sampleRate, int channels, int audioBitrate, uint8_t *audioData, size_t audioSize) { AVCodecContext *audioCodec; AVCodec *codec; uint8_t *buf; int bufSize, frameBytes; avcodec_register_all(); //Set up audio encoder codec = avcodec_find_encoder(CODEC_ID_AAC); if (codec == NULL) return; audioCodec = avcodec_alloc_context(); audioCodec->bit_rate = audioBitrate; audioCodec->sample_fmt = SAMPLE_FMT_S16; audioCodec->sample_rate = sampleRate; audioCodec->channels = channels; audioCodec->profile = FF_PROFILE_AAC_MAIN; audioCodec->time_base = (AVRational){1, sampleRate}; audioCodec->codec_type = CODEC_TYPE_AUDIO; if (avcodec_open(audioCodec, codec) < 0) return; bufSize = FF_MIN_BUFFER_SIZE * 10; buf = (uint8_t *)malloc(bufSize); if (buf == NULL) return; frameBytes = audioCodec->frame_size * audioCodec->channels * 2; while (audioSize >= frameBytes) { int packetSize; packetSize = avcodec_encode_audio(audioCodec, buf, bufSize, (short *)audioData); printf("encoder returned %d bytes of data\n", packetSize); audioData += frameBytes; audioSize -= frameBytes; } } int main() { FILE *stream = fopen("audio.pcm", "rb"); size_t size; uint8_t *buf; if (stream == NULL) { printf("Unable to open file\n"); return 1; } fseek(stream, 0, SEEK_END); size = ftell(stream); fseek(stream, 0, SEEK_SET); buf = (uint8_t *)malloc(size); fread(buf, sizeof(uint8_t), size, stream); fclose(stream); EncodeTest(32000, 2, 448000, buf, size); }

    Read the article

  • Can printf change its parameters??

    - by martani_net
    EDIT: complete code with main is here http://codepad.org/79aLzj2H and once again this is were the weird behavious is happening for (i = 0; i<tab_size; i++) { //CORRECT OUTPUT printf("%s\n", tableau[i].capitale); printf("%s", tableau[i].pays); printf("%s\n", tableau[i].commentaire); //WRONG OUTPUT //printf("%s --- %s --- %s |\n", tableau[i].capitale, tableau[i].pays, tableau[i].commentaire); } I have an array of the following strcuture struct T_info { char capitale[255]; char pays[255]; char commentaire[255]; }; struct T_info *tableau; This is how the array is populated int advance(FILE *f) { char c; c = getc(f); if(c == '\n') return 0; while(c != EOF && (c == ' ' || c == '\t')) { c = getc(f); } return fseek(f, -1, SEEK_CUR); } int get_word(FILE *f, char * buffer) { char c; int count = 0; int space = 0; while((c = getc(f)) != EOF) { if (c == '\n') { buffer[count] = '\0'; return -2; } if ((c == ' ' || c == '\t') && space < 1) { buffer[count] = c; count ++; space++; } else { if (c != ' ' && c != '\t') { buffer[count] = c; count ++; space = 0; } else /* more than one space*/ { advance(f); break; } } } buffer[count] = '\0'; if(c == EOF) return -1; return count; } void fill_table(FILE *f,struct T_info *tab) { int line = 0, column = 0; fseek(f, 0, SEEK_SET); char buffer[MAX_LINE]; char c; int res; int i = 0; while((res = get_word(f, buffer)) != -999) { switch(column) { case 0: strcpy(tab[line].capitale, buffer); column++; break; case 1: strcpy(tab[line].pays, buffer); column++; break; default: strcpy(tab[line].commentaire, buffer); column++; break; } /*if I printf each one alone here, everything works ok*/ //last word in line if (res == -2) { if (column == 2) { strcpy(tab[line].commentaire, " "); } //wrong output here printf("%s -- %s -- %s\n", tab[line].capitale, tab[line].pays, tab[line].commentaire); column = 0; line++; continue; } column = column % 3; if (column == 0) { line++; } /*EOF reached*/ if(res == -1) return; } return ; } Edit : trying this printf("%s -- ", tab[line].capitale); printf("%s --", tab[line].pays); printf("%s --\n", tab[line].commentaire); gives me as result -- --abi -- Emirats arabes unis I expect to get Abu Dhabi -- Emirats arabes unis -- Am I missing something?

    Read the article

  • Siebel Troubleshooting : An ODBC error occurred; SBL-GEN-03006: Error calling function: DICFindTable m_pReqTbl

    - by Giri Mandalika
    Symptom: A newly installed Siebel application server fails to start despite successful ODBC connectivity to the database. SRProc process logs ODBC error messages similar to the following: Message: GEN-13, Additional Message: dict-ERR-1109: Unable to read value from export file (Data length (32) Column definition (3)). Message: GEN-13, Additional Message: dict-ERR-1107: Unable to read row 0 from export file (UTLDataValRead pBuf, col 4 ). GenericLog GenericError 1 0002157.. 11-11-18 13:28 Message: Generated SQL statement:, Additional Message: SQLFetch: SELECT RDOBJ.DOCK_ID, RDOBJ.RELATED_DOCK_ID, RDOBJ.SQL_STATEMENT, RDOBJ.CHECK_VISIBILITY, 'N', RDOBJ.COMMENTS, RDOBJ.ACTIVE, RDOBJ.SEQUENCE, RDOBJ.VIS_STRENGTH, RDOBJ.REL_VIS_STRENGTH, RDOBJ.VIS_EVT_COLS FROM ORAPERF.S_DOCK_REL_DOBJ RDOBJ, ORAPERF.S_DOCK_OBJECT DOBJ WHERE RDOBJ.REPOSITORY_ID = (SELECT ROW_ID FROM ORAPERF.S_REPOSITORY WHERE NAME = ?) AND DOBJ.ROW_ID = RDOBJ.DOCK_ID AND (DOBJ.INACTIVE_FLG = 'N' OR DOBJ.INACTIVE_FLG IS NULL) AND (RDOBJ.INACTIVE_FLG = 'N' OR RDOBJ.INACTIVE_FLG IS NULL) Message: Error: An ODBC error occurred, Additional Message: Function: DICGetRDObjects; ODBC operation: SQLFetch Message: GEN-13, Additional Message: dict-ERR-1109: Unable to read value from export file (UTLCompressFRead (fseek)). Message: GEN-13, Additional Message: dict-ERR-1107: Unable to read row 0 from export file (UTLDataValRead pBuf, col 0 ). Message: GEN-10, Additional Message: Calling Function: DICLoadDObjectInfo; Called Function: Calling DICGetRDObjects Message: GEN-10, Additional Message: Calling Function: DICLoadDict; Called Function: DICLoadDObjectInfo GenericError (srpdb.cpp (860) err=3006 sys=2) SBL-GEN-03006: Error calling function: DICFindTable m_pReqTbl (srpsmech.cpp (74) err=3006 sys=0) SBL-GEN-03006: Error calling function: DICFindTable m_pReqTbl (srpmtsrv.cpp (107) err=3006 sys=0) SBL-GEN-03006: Error calling function: DICFindTable m_pReqTbl (smimtsrv.cpp (1203) err=3006 sys=0) SBL-GEN-03006: Error calling function: DICFindTable m_pReqTbl SmiLayerLog Error Terminate process due to unrecoverable error: 3006. (Main Thread) An inconsistent or corrupted dictionary file "diccache.dat" is likely the cause. Solution: Stop the application server and manually kill the remaining Siebel application specific processes eg., stop_server all pkill siebmtsh pkill siebproc .. Remove $SIEBEL_HOME/bin/diccache.dat file. It will be re-generated during the application server startup Start the application server start_server all

    Read the article

  • getline at a certain line for file IO

    - by BSchlinker
    Is there anyway to use getline to read a specific line within a file? For instance, to immediately read line #20? It seems inefficient to do any type of look to read and discard earlier lines. I know about fseek, but there is no guarantee that the records will be the same length on each line. I imagine this is simply what is required in order to find lines. After all, to know when the end of the line has been reached, it needs to find the break line character, so it makes sense for it to need to read each line. Just wondering if there was any quicker method.

    Read the article

  • Sending multipart response for downloads in Zend Framework

    - by takeshin
    I'm sending files in action helper for downloads (in parts if needed) like this: ... $response->sendHeaders(); $chunksize = 1 * (1024 * 1024); $bytesSent = 0; if ($httpRange) { fseek($file, $range); } while(!feof($file) && (!connection_aborted() && ($bytesSent < $newLength)) ) { $buffer = fread($file, $chunksize); // $response->appendBody($buffer); // this would be better print($buffer); flush(); $bytesSent += strlen($buffer); } fclose($file); I suspect that better way would be to make use of $response object instead of print. Which is the recommended way to send big response objects using Zend Framework?

    Read the article

  • feof() in C file handling

    - by Neeraj
    I am reading a binary file byte-by-byte,i need determine that whether or not eof has reached. feof() doesn't works as "eof is set only when a read request for non-existent byte is made". So, I can have my custom check_eof like: if ( fread(&byte,sizeof(byte),1,fp) != 1) { if(feof()) return true; } return false; But the problem is, in case when eof is not reached, my file pointer is moved a byte ahead. So a solution might be to use ftell() and then fseek() to get it to correct position. Another solution might be to buffer the byte ahead in some temporary storage. Any better solutions?

    Read the article

  • Can I make valgrind ignore glibc libraries?

    - by Jack
    Is it possible to tell valgrind to ignore some set of libraries? Specifically glibc libraries.. Actual Problem: I have some code that runs fine in normal execution. No leaks etc. When I try to run it through valgrind, I get core dumps and program restarts/stops. Core usually points to glibc functions (usually fseek, mutex etc). I understand that there might be some issue with incompatible glibc / valgrind version. I tried various valgrind releases and glibc versions but no luck. Any suggestions?

    Read the article

  • Leak caused by fread

    - by Jack
    I'm profiling code of a game I wrote and I'm wondering how it is possible that the following snippet causes an heap increase of 4kb (I'm profiling with Heapshot Analysis of Xcode) every time it is executed: u8 WorldManager::versionOfMap(FILE *file) { char magic[4]; u8 version; fread(magic, 4, 1, file); <-- this is the line fread(&version,1,1,file); fseek(file, 0, SEEK_SET); return version; } According to the profiler the highlighted line allocates 4.00Kb of memory with a malloc every time the function is called, memory which is never released. This thing seems to happen with other calls to fread around the code, but this was the most eclatant one. Is there anything trivial I'm missing? Is it something internal I shouldn't care about? Just as a note: I'm profiling it on an iPhone and it's compiled as release (-O2).

    Read the article

  • valgrind - ignore glibc functions?

    - by Jack
    Is it possible to tell valgrind to ignore some set of libraries? Specifically glibc libraries.. Actual Problem: I have some code that runs fine in normal execution. No leaks etc. When I try to run it through valgrind, I get core dumps and program restarts/stops. Core usually points to glibc functions (usually fseek, mutex etc). I understand that there might be some issue with incompatible glibc / valgrind version. I tried various valgrind releases and glibc versions but no luck. Any suggestions?

    Read the article

1 2 3  | Next Page >