473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing strings instead of rabish to file using fprintf

I am writing stings ((*cust).name), ((*cust).addres s)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp \iti01\ch10\ex0 9_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM

*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

};

main()
{
clrscr();
printf ("-----------------------------------------------------------------------------");
printf ( "\nThis is run of program") ;
printf ( "E:\programs\\c pp\\iti01\\ch09 \\ex09_5p1.cpp\ n");
printf ( "
-------------------------------------------\n");

void customer_input( struct customer_record *cust);
struct customer_record customer;
char another_custome r;

//open file for output
FILE *fp_rental;

if ((fp_rental=fop en("input","w") )==NULL)
{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
exit (0);
}

// do while more customers

do {
//input customer date
customer_input( &customer);
//write customer date to file
fprintf(fp_rent al,"%4d %2d %c %s %s",customer) ;
printf("\n Another customer");
scanf("\n");
scanf("%c",&ano ther_customer);
} while ((another_custo mer)=='y');
//write end of record
fprintf(fp_rent al,"%4d %2 d %c %s %s",9999,99,' ',' ',' ');
//clsoe files
fclose(fp_renta l);
return 0;
}

void customer_input( struct customer_record *cust)
{
printf("\n Enter customer number : ");
scanf ("%4d",&(*cust) .customer_no);
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust) .no_of_weeks);
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust). tv_type);
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust). name);
gets((*cust).na me);
printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust). address);
gets((*cust).ad dress);
}
Nov 14 '05 #1
6 3500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hp******@yahoo. com wrote:
I am writing stings ((*cust).name), ((*cust).addres s)to a file using
fgets
I hope not. fgets() doesn't write to files, it reads from them.
but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp \iti01\ch10\ex0 9_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM

*/
#include <conio.h>
conio.h is not a standard C header. I don't know what it defines (nor do
I care); it could define something that causes a problem with your program.
#include <stdio.h>
#include <stdlib.h>
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

};

main()
ITYM
int main(void)
which would be the closest to your intent for a C99 compliant compiler.
If you aren't using a C99 compliant compiler, then this program isn't
written in C, or at least is compilable as a C program.
{
clrscr();
clrscr() is not a standard C function, and you haven't provided the
source for it. This function could cause a problem with your program,
and we won't be able to help diagnose it.

printf ("-----------------------------------------------------------------------------"); printf ( "\nThis is run of program") ;
printf ( "E:\programs\\c pp\\iti01\\ch09 \\ex09_5p1.cpp\ n");
You really need to understand escape sequences. What will the escape
sequence \p (as in "E:\p") print?
printf ( "
-------------------------------------------\n");

void customer_input( struct customer_record *cust);
struct customer_record customer;
char another_custome r;
I hope that you are compiling with a C99 compliant compiler, otherwise
this is illegal, and would cause compilation to fail.
//open file for output
FILE *fp_rental;

if ((fp_rental=fop en("input","w") )==NULL)
{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
exit (0);
}

// do while more customers

do {
//input customer date
customer_input( &customer);
//write customer date to file
fprintf(fp_rent al,"%4d %2d %c %s %s",customer) ;
Here's the line that's causing your problem.

You ask fprintf() to print
a) a four digit number,
b) a two digit number,
c) a single character,
d) a string, and
e) another string
but you don't give fprintf() any of those things. Instead, you give
fprintf() a "customer". You've just invoked "undefined behaviour", where
the program can do /anything/, including generating inappropriate results.

You really mean to write
fprintf(fp_rent al,"%4d %2d %c %s %s",
customer.custom er_no,
customer.no_of_ weeks,
customer.tv_typ e,
customer.name,
customer.addres s);

printf("\n Another customer");
scanf("\n");
scanf("%c",&ano ther_customer);
} while ((another_custo mer)=='y');
//write end of record
fprintf(fp_rent al,"%4d %2 d %c %s %s",9999,99,' ',' ',' ');
Close, but no cigar.
1) you have an improper format string: %2 isn't proper
2) the third and fourth data arguments are not strings, they are single
characters, and
3) you have one too many data arguments for the format string given

//clsoe files
fclose(fp_renta l);
return 0;
}

void customer_input( struct customer_record *cust)
{
printf("\n Enter customer number : ");
scanf ("%4d",&(*cust) .customer_no);
1) what if I enter "abcdefgh" to the customer number prompt?
2) &(*cust).custom er_no ?? ITYM &(cust->customer_no)
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust) .no_of_weeks);
same as above
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust). tv_type);
same as above
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust). name);
gets((*cust).na me);
same as above, with an additional caveat:
It isn't a good idea to mix input methods. It can work, but you /really/
have to understand what you are doing in order to make it work
correctly, and you haven't demonstrated that you understand what you are
doing yet.

printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust). address);
gets((*cust).ad dress);
same as above
}

- --

Lew Pitcher, IT Consultant, Enterprise Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFArhyaagV FX4UWr64RAgM0AK DbSs73zJJ4Kg7pA FXNstaFIqiPjQCa Ak75
NJGZFZrQw+fpsh+ dQlkDXo0=
=pyVk
-----END PGP SIGNATURE-----
Nov 14 '05 #2
hp******@yahoo. com wrote:
I am writing stings ((*cust).name), ((*cust).addres s)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
Lew Pitcher has already posted an excellent reply, so I will
indicate some alternative methods for what you are doing.


/* Book name :
File name : E:\programs\cpp \iti01\ch10\ex0 9_5p1.cpp Paths should not be inside files. Files don't know where they
are located. Their location may change without their knowledge.
If this file moves, then this comment will have to change.

Program discription: Adding name,Address to customer_record SETUP
PROGRAM

*/
#include <conio.h> This is a platform specific header file.
I suggest you do without it.

#include <stdio.h>
#include <stdlib.h>
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

}; "Magic Numbers". That's what 40 and 60 are called above.
A common guideline is to use named constants:
#define MAX_NAME_LENGTH 40
#define MAX_ADDRESS_LEN GTH 60

....
char name[MAX_NAME_LENGTH];
char address[MAX_ADDRESS_LEN GTH];

Also, is tv_type a letter or just a small number or perhaps
an enumeration? If it is a number, use either int or unsigned
int. Unless you are writing code for a system that has a small
amount of memory, don't use short or char for numbers. For
many platforms, the processor is more efficient using int than
char or short.

If your no_of_weeks field cannot be negative, I suggest you
use an unsigned int. I haven't run across a occasion where
someone checked out a video for -2 weeks.

And similarly with customer number. However, some systems use
a negative customer number as an indicator. (Such as customer
doesn't exist anymore.)


main()
{
clrscr(); No need to clear the screen. Also, on windowing platforms,
are you clearing the whole screen or the window?

printf ("-----------------------------------------------------------------------------");
printf ( "\nThis is run of program") ;
printf ( "E:\programs\\c pp\\iti01\\ch09 \\ex09_5p1.cpp\ n");
printf ( "
-------------------------------------------\n");
Hey, try this one out:
static const char program_header_ text[] =
"--------------------------------------------------\n"
"This is run of program ex09_5p1.cpp\n"
"--------------------------------------------------\n";
fwrite(program_ header_txt,
sizeof(char), /* to be explicit */
sizeof(program_ header_text) - 1, /* don't write the '\0' */
stdout);

or this:
puts(program_he ader_text);

void customer_input( struct customer_record *cust);
struct customer_record customer;
char another_custome r;

//open file for output
FILE *fp_rental;

if ((fp_rental=fop en("input","w") )==NULL) To make your program easier to read, split this into more
lines:
const char OUTPUT_FILENAME[] = "input";

fp_rental = fopen(OUTPUT_FI LENAME, "w");
if (!fp_rental)
{
fprintf(stderr, "\nCannot open %s for output\n",
OUTPUT_FILENAME );
fprintf(stderr, "Program terminated.\n") ;
return EXIT_FAILURE;
}
Using a constant literal for the filename allows you to
only have to change one line when that filename is modified.

The main() is a function, so it must return a value.
Two defined values are EXIT_SUCCESS and EXIT_FAILURE, which
are defined in <stdlib.h>.

{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
exit (0);
}

// do while more customers

do {
//input customer date
customer_input( &customer);
//write customer date to file
fprintf(fp_rent al,"%4d %2d %c %s %s",customer) ; This should only be performed if the customer data is valid.

printf("\n Another customer");
scanf("\n");
scanf("%c",&ano ther_customer);
} while ((another_custo mer)=='y'); while ( toupper(another _customer) == 'Y');
or
while (tolower(anothe r_customer) == 'y');

//write end of record
fprintf(fp_rent al,"%4d %2 d %c %s %s",9999,99,' ',' ',' '); Magic Numbers and literals. Use named constants.
//clsoe files
fclose(fp_renta l);
return 0; return EXIT_SUCCESS;
}

void customer_input( struct customer_record *cust)
{
printf("\n Enter customer number : ");
scanf ("%4d",&(*cust) .customer_no);
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust) .no_of_weeks);
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust). tv_type);
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust). name);
gets((*cust).na me);
printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust). address);
gets((*cust).ad dress);
}


The scanf function is evil, see the C language
FAQ below.

I suggest that if you have a special input function
for the customer_record , you have a complementary
output function also (and use it). Many programmers
and designers have one set of I/O functions for
file I/O and another for User Interface I/O.

As a matter of encapsulation, I suggest that you
place all of the customer functions into one
module. Create a header file that defines the
customer_record and declares the functions.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #3
In 'comp.lang.c', eh***********@y ahoo.com (hp******@yahoo .com) wrote:
/* Book name :
File name : E:\programs\cpp \iti01\ch10\ex0 9_5p1.cpp
Why .cpp ? Are you writing in C of not?
Program discription: Adding name,Address to customer_record SETUP
PROGRAM
You are not 'adding', but you create a new file each time. using fopen()
with "a" instead of "w" will add.
*/
#include <conio.h>
Non standard and useless.
#include <stdio.h>
#include <stdlib.h> struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

};

main()
Prefer

int main ()
or
int main (void)
{
clrscr();
Get rid of this.
printf
("-----------------------------------------------------------------------
------"); printf ( "\nThis is run of program") ;
printf ( "E:\programs\\c pp\\iti01\\ch09 \\ex09_5p1.cpp\ n");
printf ( "
-------------------------------------------\n");
The __FILE__ macro gives the name of the current file.
void customer_input( struct customer_record *cust);
Don't put prototypes in a function. They belong to a header. In your case,
you just have to follow the "define before use" design rule and to change
your layout accordingly. Local functions should be defined with 'static'.
struct customer_record customer;
char another_custome r;

//open file for output
Keep in mind that the // comment style has not to be supported by C90
compilers
FILE *fp_rental;

if ((fp_rental=fop en("input","w") )==NULL)
"a" is probably better for your case...
{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
The '\n' character is the end of line indicator. Why putting it at the
beginning of the line?

"Sounds illogical, capt'ain". -- Spock.
exit (0);
The standard error value is EXIT_FAILURE...
}

// do while more customers

do {
//input customer date
customer_input( &customer);
//write customer date to file
fprintf(fp_rent al,"%4d %2d %c %s %s",customer) ;
The C language is not that clever! Each "%..." field must have a, explicit
value.

To be able to retrieve the data easily, I suggest a CSV (Comma Separated
Values) format terminated by a '\n' (one by record). In that case, you don't
need the width formatters :

"%d,%d,%c,%s,%s "
printf("\n Another customer");
scanf("\n");
Ugly! scanf() is not designed to get data from a human ('f' means
'formatted'. Fortunately, humans are not (yet) formatted.)
scanf("%c",&ano ther_customer);
You need to write your own input functions based on fgetc() or fgets().
} while ((another_custo mer)=='y');
//write end of record
fprintf(fp_rent al,"%4d %2 d %c %s %s",9999,99,' ',' ',' ');
The record format should be 'factorised' (a macro is just fine)

You don't expect more than 9999 customers for the progam life ? Software can
survive on different hardware for decades.
//clsoe files
fclose(fp_renta l);
return 0;
}

void customer_input( struct customer_record *cust)
{
printf("\n Enter customer number : ");
You need a fflush (stdout) to be sure that the caracters are outputted on
time.
scanf ("%4d",&(*cust) .customer_no);
Once again, you need a more solid function of your own, based on fgets() and
strtoul(), for example.
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust) .no_of_weeks);
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust). tv_type);
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust). name);
gets((*cust).na me);
No. it's a bug. You really have to learn more about fgets().
printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust). address);
gets((*cust).ad dress);
}


Try this. Missing code is here:

http://mapage.noos.fr/emdel/clib.htm
Module IO

/* Book name :
File name :
Program discription: Adding name,Address to customer_record SETUP
PROGRAM

*/
#include <stdio.h>
#include <stdlib.h>

#include "ed/inc/io.h"

struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

};

static void customer_input (struct customer_record *cust)
{
unsigned long n;

printf (" Enter customer number: ");
fflush (stdout);
get_ul (&n);
cust->customer_no = (int) n;

printf (" Enter number of weeks: ");
fflush (stdout);
get_ul (&n);
cust->no_of_weeks = (int) n;

printf (" Enter tv type: ");
fflush (stdout);
cust->tv_type = get_c ();

printf (" Enter customer name: ");
fflush (stdout);
get_s (cust->name, sizeof cust->name);

printf ("Enter customer address: ");
fflush (stdout);
get_s (cust->address, sizeof cust->address);
}

int main (void)
{
int ret = EXIT_SUCCESS;

printf ("-------------------------------------------\n"
"This is run of program '%s'\n"
"-------------------------------------------\n"
,__FILE__);
{

/* open file for output */
FILE *fp_rental = fopen ("input", "w");

if (fp_rental != NULL)
{
#define RECORD_FORMAT "%4d,%2d,%c,%s, %s\n"
struct customer_record customer;
char another_custome r;

/* do while more customers */
do
{
/* input customer date */
customer_input (&customer);
/* write customer date to file */
fprintf (fp_rental
,RECORD_FORMAT
,customer.custo mer_no
,customer.no_of _weeks
,customer.tv_ty pe
,customer.name
,customer.addre ss
);

printf ("Another customer (y/n): ");
fflush (stdout);

another_custome r = get_c ();
}
while ((another_custo mer) == 'y');

/* write end of record */
fprintf (fp_rental
,RECORD_FORMAT
,9999, 99, ' ', " ", " ");

/* close files */
fclose (fp_rental);
#undef RECORD_FORMAT
}
else
{
printf ("can not open 'input' for output\n");
printf ("Program terminated\n");
ret = EXIT_FAILURE;
}
}
return ret;
}
--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #4
eh***********@y ahoo.com (hp******@yahoo .com) wrote in message news:<7e******* *************** ****@posting.go ogle.com>...
I am writing stings ((*cust).name), ((*cust).addres s)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
[redacted]


1. Opening a file named "input" for output is counterintuitiv e and
not good for maintainability .
2. Learn about the -> operator, for readability purposes, if nothing
else.
Nov 14 '05 #5
In 'comp.lang.c', Thomas Matthews
<Th************ *************** *@sbcglobal.net > wrote:
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

};

"Magic Numbers". That's what 40 and 60 are called above.
A common guideline is to use named constants:
#define MAX_NAME_LENGTH 40
#define MAX_ADDRESS_LEN GTH 60

...
char name[MAX_NAME_LENGTH];
char address[MAX_ADDRESS_LEN GTH];


For this example, I disagree. The important thing is that the so-called magic
number (that have to exist in somme manner) is defined once and only once.
BTW, isn't the array itself the best place to define its size ?

struct customer_record
{
...
char name[40];
char address[60];
};

Is just fine to me, self commenting and easy to maintain. If you want the
size somewhere else, you know how to use sizeof properly.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #6
eh***********@y ahoo.com (hp******@yahoo .com) wrote in message news:<7e******* *************** ****@posting.go ogle.com>...
I am writing stings ((*cust).name), ((*cust).addres s)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp \iti01\ch10\ex0 9_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM

*/
#include <conio.h>
Not standard and not needed here.
#include <stdio.h>
#include <stdlib.h>
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
char name[40];
char address[60];

};

main()
int main(void)
{
clrscr();
clrscr() is non-standard.
printf ("-----------------------------------------------------------------------------");
printf ( "\nThis is run of program") ;
printf ( "E:\programs\\c pp\\iti01\\ch09 \\ex09_5p1.cpp\ n");
printf ( "
-------------------------------------------\n");

void customer_input( struct customer_record *cust);
struct customer_record customer;
char another_custome r;

//open file for output
FILE *fp_rental;

if ((fp_rental=fop en("input","w") )==NULL)
{
printf ("\n can not open 'input' for output");
printf ("\n Program terminated");
exit (0);
}

// do while more customers
Not a nit, just an observation: Use /* */ comments in C.

do {
//input customer date
customer_input( &customer);
//write customer date to file
fprintf(fp_rent al,"%4d %2d %c %s %s",customer) ;
printf("\n Another customer");
scanf("\n");
scanf("%c",&ano ther_customer);
The scanf() function is tricky to use correctly. I recommend for
amateurs to avoid it and use fgets() plus any of (sscanf, strtod,
strtoul) or similar functions. You never know what kind of input
you're going to get.
} while ((another_custo mer)=='y');
//write end of record
fprintf(fp_rent al,"%4d %2 d %c %s %s",9999,99,' ',' ',' '); ^-- bug here. ^---^-- must be
strings, not

characters, to match
the format
specifier
in
fprintf().
//clsoe files
fclose(fp_renta l);
return 0;
}

void customer_input( struct customer_record *cust)
{
printf("\n Enter customer number : ");
scanf ("%4d",&(*cust) .customer_no);
printf("\n Enter number of weeks : ");
scanf ("%2d",&(*cust) .no_of_weeks);
printf("\n Enter tv type : ");
scanf ("\n");
scanf ("%c",&(*cust). tv_type);
printf("\n Enter customer name : ");
scanf ("\n");
//scanf ("%c",&(*cust). name);
gets((*cust).na me);
printf("\n Enter customer address : ");
scanf ("\n");
//scanf ("%s",&(*cust). address);
gets((*cust).ad dress);
Do not use gets(), for it is a tool of the Devil. Use fgets() instead.

I also recommend fflush(stdout); after all the printf()s.
}


I'm sure the listmates will have more.

Gregory Pietsch
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3778
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two days and would appreciate this group's helpful expertise. My problem may be related to mixing the C and C++ languages together. Namely, I have a struct which I cannot change (as legacy code) similiar to this (I will change the names throughout as...
5
4351
by: zambak | last post by:
Hi I have assignment for some wierd compression alghoritam that will read in from a file convert characters to 5 bit codes and then write out compressed version of the original file. For example if input file contains string "AMIR" and the codes are A=0, M=12,I=8,R=17 i am supposed to write out 3 byte file The problem? How do I figure out shifting because I can only write out bytes
9
1668
by: Craig | last post by:
Hello friends at comp.lang.c, I'm trying to combine 2 strings with a newline character at the end to write to a file. When I view the file, the messages run together and some of the str string is cut-off. A portion of the code is below. Any help would be appreciated. #define MAX_SIZE 256 char str; char lev = "INFO: ";
2
4200
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain how to use Command-Line Arguments inside C program.
5
6214
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now is as follows: - i am trying to write code that will take any number of text inputs (names of other text files) and put them into a file line-by-line at the users request. meaning, i want the user to be able to type the strings and enter them...
2
22605
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be read (the file will be written by only this program); file can be either in text or binary (preferably binary as the files may be read repeatedly); the amount and size of strings in the array won't be known until run time (in the example I have it in...
12
5092
by: hemant.gaur | last post by:
I have an application which writes huge number of bytes into the binary files which is just some marshalled data. int len = Data.size(); //arrary size for (int i = 0; i < len; ++i) fwrite(&Data, 1, 1, f); now after running this for long time and pushing millions of bytes, It once misses writing the last byte of fData. Then the further push of bytes is again correct. As i am not using the return value for the
2
2257
by: mauricesmith42 | last post by:
Sorry i know this is rather large to be posting, but in order to understand the question you have to see all the code //#include <windows.h> //needed for opening folders #include <stdlib.h> //needed for converting integers to strings #include <iostream> //needed for in/out commands ie. cin/cout #include <fstream> //needed to open readable/writeable files ie. ifstream/ofstream #include <string> //needed to create strings from...
4
3682
by: Jim | last post by:
Hi There, I'm trying to read a file character by character. When I write the file out, there is one extra character which shows on the screen as a solid circle with a small question mark in the middle. Here is what I have: infile = fopen("encrypted.txt", "r"); outfile = fopen("plain.txt", "w");
0
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.