Learn how to use your debugger. First, this isn't C code. In C all variables must be defined at the top of the function. But you define two arrays after you say option='0'; Second, you can't define the two arrays on the same line of code. At least you can't in C89 which I am using. Define the arrays on separate ... |
|
|
I have been having a very peculiar issue from a long time. I have an application where multiple clients read from a shared set of files. When a record is changed, sometimes the win9x clients still read the old data (if it was read earlier) and this is causing data corruption. WinNT clients inlcuding windows2000 & XP do not have this ... |
|
Code: #include #include int main() { struct BITMAPFILEHEADER{ unsigned short type; unsigned long size; unsigned short reserved1; unsigned short reserved2; unsigned long offsetbits; }; struct BITMAPINFOHEADER{ unsigned long size; unsigned long width; unsigned long height; unsigned short planes; unsigned short bitcount; unsigned long compression; unsigned long sizeimage; long xpelspermeter; long ypelspermeter; unsigned long colorsused; unsigned long colorsimportant; }; struct SINGLE_PIXEL{ unsigned ... |
Hi all, I am facing some weird (at least that seems to me) phenomenon in running my code. I have a code, which needs to read inputs from files, processes the data and output it into a file as well. I have been trying with smaller files and that seems to work. So, I was thinking to do an actual run ... |
|
#include #include #define ROWS 3 #define COLUMNS 3 int main (int argc, char *argv[]) { FILE *fp; char array[ROWS][COLUMNS]; // int *ptr[ROWS] int i, sum = 0; int avg[ROWS], nums[3]; int cnt; //open the file for reading if (argc > 1) { fp = fopen (argv[1], "r"); while (fgets (array[i], COLUMNS, fp) != NULL) { // ptr[i] = array[i]; ... |
Hi guys. I'm working on a program that basically functions as a cookie cutter for GeoTIFF (geographic TIFF) images based on a shapefile (just a file with some shape information, like it sounds). It has worked reliably with most shapefiles, but the one I'm currently using is causing some weird problems reprojecting the projection file. My projection code is based off ... |
#include #include #include char *slurpfile (const char *file) { char *r; struct stat info; FILE *in = fopen(file, "r"); if (!in) return NULL; stat(file,&info); r = malloc((int)info.st_size+1); // option: error handling malloc fread(r,info.st_size,1,in); fclose(in); return r; } int main(int argc, const char *argv[]) { char *contents = slurpfile(argv[1]); printf("%s",contents); free(contents); return 0; } |
In my opinion, the correct thing to do is inform the user that there was an error reading the file, then exit the program. It's not really much use trying to reopen and re-read the file since your program has no way of knowing what's wrong. Better to tell the user there's a problem. The user can then try to figure ... |
|
|
Error in reading from file Well, i'm doing a project for my university, and i've got some mistakes, when i try to read the values from files. please someone take a look and show me possible errors. since thank. Code: #include #include #include #include //declarao de estruturas typedef struct{ float carro, moto, mensal; // definicao de preo ... |
//Reads data from a sequential file #include int main(){ int account; float money; char name[30]; FILE *cfPtr; if ((cfPtr = fopen("clients.dat","r") == NULL) printf("Unable to find or open the file") else { printf("%-10s%-13s%s\n", "Account", "Name", "Money"); fscanf(cfPtr, "%d%s%f", &account, name, &money); while (!feof(cfPtr)){ printf("%-10d%-13s%7.2f\n", account, name, money); fscanf(cfPtr, "%d%s%f", &account, name, &money); } fclose(cfPtr); } return 0; } |
Hello, When i try to compile my simple project that shows some records of an sequencial file created on my another program the g++ gave me some errors, what is wrong?, but here is the code of my project: Code: // ComplexClientFile.cpp // Programa de consulta de crdito #include using std::cerr; using std::cin; using std::cout; using std::endl; using std::fixed; using ... |
I've been assigned a program that uses templates and basically just keeps records of student grades. When I try to actually read in a record from a file, it compiles fine but gives me the following linking error: Quote: driver2.obj : error LNK2001: unresolved external symbol "class std::basic_istream > & __cdecl operator>>(class std::basic_istream > &,class StudentRec const &)" (??5@YAAAV?$basic_ ... |
|
Hello, I am having trouble with a simple math operation after reading from a file. If a particular condition is met, i am copying a number(7 positions), starting from position 31. My aim is to sum all these numbers when the condition is met. I am testing the code on a file where the condition is met only once, as follows: ... |
istream fin; fin = open( "input.num", ios::in ); if( !fin ) ... // Error fin.seekg( 0, ios::end ) // Find file size fileSize = fin.tellg( ); if( fileSize < sizeof( int )) // Need atleast one int ...// Error fin.seekg( 0, ios::beg ); fin< |
|
If you open the file twice contemporarly (that's what I understand ...) you are in fact talking to the file system through two different channels, each of which have its own buffer, not aware of the state of the other. You read only the part that the write buffer already committed. To properly work with file (You ... |