Thread: [Dev-C++] Simple question about reading files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alain P. <ala...@ge...> - 2004-04-20 06:16:37
|
Hi all,
I have to read a file that contains binary data, including some 0xff, 0x00 and 0x1A. I tried fread and fgetc. But when the 0x1A is read, this doesn't work. For example, if you write a loop to read a file containing
0x41 0x1A 0x42 0x43 ....
The loop is like :
while (!EOF) {
fread(&mycharbuffer, 1, 1, myfile);
}
First read character is 0x41
Second read character is 0x41 ! Because the 0x1A can't be read by fread, mycharbuffer contains the previous value !!
How can I read a file so that every byte can be any value between 0x00 and 0xFF in this file ???
Thank you for any advice.
|
|
From: Rick L. <sev...@co...> - 2004-04-20 07:51:54
|
I am writing an operating system called StarFire it will be based off of dos, however the programs included with command.com (dir, echo, etc. ) will be external commands in the C:\bin folder. What functions can I use to detect arguments passed from the shell to a program. Example: [dir.exe -a C:\bin] or [dir.exe -hsx C:\bin] dir is the standard dos dir statement however i want the arguments to be: -a all files -h hidden files -s system files -x compressed files -u user files -t text files or any combination of those with only one dash. Is this possible? |
|
From: Per W. <pw...@ia...> - 2004-04-20 08:32:23
|
Note that if you make your completely own OS, you might use any method you like, since you have to implement it yourself. Alternative 2 - using msdos.sys + io.sys and just replacing the command line. One again, you might use any method you like, since msdos will only specially handle the first two arguments meaning that the command.com replacement must contain full commandl line parsing. Alternative 3 - you are still going to use command.com. Then - I haven't an old MSDOS available so I can't test - I assume you have to run your commands as dir.exe, md.exe etc, since command.com will otherwise process the built-in commands dir/echo/... as reserved words and process by itself without looking for any external program with the same name in the program path. Anyway, if you manage to start your own external programs, the command line parameters will be available exactly as if you write a normal dos or win32 command line program. /Per W On Tue, 20 Apr 2004, Rick Langschultz wrote: > I am writing an operating system called StarFire it will be based off of > dos, however the programs included with command.com (dir, echo, etc. ) will > be external commands in the C:\bin folder. What functions can I use to > detect arguments passed from the shell to a program. > > Example: [dir.exe -a C:\bin] or [dir.exe -hsx C:\bin] > > dir is the standard dos dir statement however i want the arguments to be: > -a all files > -h hidden files > -s system files > -x compressed files > -u user files > -t text files > > or any combination of those with only one dash. Is this possible? > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Siva C. <siv...@ya...> - 2004-04-20 09:46:36
|
Hello all, Don't know if this is the right place to post... How do I program the parallel port in C/C++ using Dev-C++? I am looking at WinMe/2000/NT/XP as my target platforms. Any pointers and suggestions are welcome... TIA Siva Chandra __________________________________ Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢ http://photos.yahoo.com/ph/print_splash |
|
From: Koval V. <vk...@in...> - 2004-04-20 10:23:06
|
On Tue, 20 Apr 2004 02:46:30 -0700 (PDT) Siva Chandra <siv...@ya...> wrote: > > Hello all, > > Don't know if this is the right place to post... > How do I program the parallel port in C/C++ using > Dev-C++? > I am looking at WinMe/2000/NT/XP as my target > platforms. > > Any pointers and suggestions are welcome... see project avrdude: http://savannah.nongnu.org/download/avrdude/ avrdude - programmer, that work through serial and parallel ports with some hardware. |
|
From: Matthew O. <mt...@ya...> - 2004-04-20 12:13:09
|
I think programming an OS even for fun you should
learn the basics of computer programming first.
Passing arguemtns is very elementary. In your main you
have two variables one that holds numbers of arguments
and the other an pointer to and array. That array is
actually passed to the program by the OS. Most people
use:
int main(int argc, char *argv[])
argc = number of arguments
argv = the array of arguments
Try this:
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
fprintf(stdout,
"The number of command line arguments is
%d\n",
argc);
fprintf(stdout,"The program name is
%s\n",argv[0]);
for (i = 1; i < argc; i++)
{
fprintf(stdout,"%s",argv[i]);
}
fprintf(stdout,"\n");
return 0;
}
If you do a search on OS programming your going to
find a ton of sites that will teach you the basics
step by step.
http://directory.google.com/Top/Computers/Programming/Operating_Systems/
Good luck
Matthew Ozor
--- Per Westermark <pw...@ia...> wrote:
> Note that if you make your completely own OS, you
> might use any method you
> like, since you have to implement it yourself.
>
> Alternative 2 - using msdos.sys + io.sys and just
> replacing the command
> line. One again, you might use any method you like,
> since msdos will only
> specially handle the first two arguments meaning
> that the command.com
> replacement must contain full commandl line parsing.
>
> Alternative 3 - you are still going to use
> command.com. Then - I haven't
> an old MSDOS available so I can't test - I assume
> you have to run your
> commands as dir.exe, md.exe etc, since command.com
> will otherwise process
> the built-in commands dir/echo/... as reserved words
> and process by itself
> without looking for any external program with the
> same name in the
> program path. Anyway, if you manage to start your
> own external programs,
> the command line parameters will be available
> exactly as if you write a
> normal dos or win32 command line program.
>
> /Per W
>
> On Tue, 20 Apr 2004, Rick Langschultz wrote:
>
> > I am writing an operating system called StarFire
> it will be based off of
> > dos, however the programs included with
> command.com (dir, echo, etc. ) will
> > be external commands in the C:\bin folder. What
> functions can I use to
> > detect arguments passed from the shell to a
> program.
> >
> > Example: [dir.exe -a C:\bin] or [dir.exe
> -hsx C:\bin]
> >
> > dir is the standard dos dir statement however i
> want the arguments to be:
> > -a all files
> > -h hidden files
> > -s system files
> > -x compressed files
> > -u user files
> > -t text files
> >
> > or any combination of those with only one dash.
> Is this possible?
> >
> >
> >
> >
>
-------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux
> Tutorials
> > Free Linux tutorial presented by Daniel Robbins,
> President and CEO of
> > GenToo technologies. Learn everything from
> fundamentals to system
> >
>
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> >
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
>
-------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux
> Tutorials
> Free Linux tutorial presented by Daniel Robbins,
> President and CEO of
> GenToo technologies. Learn everything from
> fundamentals to system
>
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢
http://photos.yahoo.com/ph/print_splash
|
|
From: Per W. <pw...@ia...> - 2004-04-20 12:35:50
|
Actually, depending on OS the array is _sometimes_ passed by the command
shell but for a lot of OS, the application just receives a text line and
must itself split it into arguments.
Also, processing of wildcard characters on the command line is performed
at different locations depending on OS.
/Per W
On Tue, 20 Apr 2004, Matthew Ozor wrote:
> I think programming an OS even for fun you should
> learn the basics of computer programming first.
> Passing arguemtns is very elementary. In your main you
> have two variables one that holds numbers of arguments
> and the other an pointer to and array. That array is
> actually passed to the program by the OS. Most people
> use:
>
> int main(int argc, char *argv[])
> argc =3D number of arguments
> argv =3D the array of arguments
>
> Try this:
>
> #include <stdio.h>
>
> int main(int argc, char *argv[])
> {
> int i;
> fprintf(stdout,
> "The number of command line arguments is
> %d\n",
> argc);
> fprintf(stdout,"The program name is
> %s\n",argv[0]);
>
> for (i =3D 1; i < argc; i++)
> {
> fprintf(stdout,"%s",argv[i]);
> }
> fprintf(stdout,"\n");
> return 0;
> }
>
>
> If you do a search on OS programming your going to
> find a ton of sites that will teach you the basics
> step by step.
>
> http://directory.google.com/Top/Computers/Programming/Operating_Systems/
>
> Good luck
> Matthew Ozor
> --- Per Westermark <pw...@ia...> wrote:
> > Note that if you make your completely own OS, you
> > might use any method you
> > like, since you have to implement it yourself.
> >
> > Alternative 2 - using msdos.sys + io.sys and just
> > replacing the command
> > line. One again, you might use any method you like,
> > since msdos will only
> > specially handle the first two arguments meaning
> > that the command.com
> > replacement must contain full commandl line parsing.
> >
> > Alternative 3 - you are still going to use
> > command.com. Then - I haven't
> > an old MSDOS available so I can't test - I assume
> > you have to run your
> > commands as dir.exe, md.exe etc, since command.com
> > will otherwise process
> > the built-in commands dir/echo/... as reserved words
> > and process by itself
> > without looking for any external program with the
> > same name in the
> > program path. Anyway, if you manage to start your
> > own external programs,
> > the command line parameters will be available
> > exactly as if you write a
> > normal dos or win32 command line program.
> >
> > /Per W
> >
> > On Tue, 20 Apr 2004, Rick Langschultz wrote:
> >
> > > I am writing an operating system called StarFire
> > it will be based off of
> > > dos, however the programs included with
> > command.com (dir, echo, etc. ) will
> > > be external commands in the C:\bin folder. What
> > functions can I use to
> > > detect arguments passed from the shell to a
> > program.
> > >
> > > Example: [dir.exe -a C:\bin] or [dir.exe
> > -hsx C:\bin]
> > >
> > > dir is the standard dos dir statement however i
> > want the arguments to be:
> > > -a all files
> > > -h hidden files
> > > -s system files
> > > -x compressed files
> > > -u user files
> > > -t text files
> > >
> > > or any combination of those with only one dash.
> > Is this possible?
> > >
> > >
> > >
> > >
> >
> -------------------------------------------------------
> > > This SF.Net email is sponsored by: IBM Linux
> > Tutorials
> > > Free Linux tutorial presented by Daniel Robbins,
> > President and CEO of
> > > GenToo technologies. Learn everything from
> > fundamentals to system
> > >
> >
> administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE:
> > http://www23.brinkster.com/noicys/devcpp/ub.htm
> > >
> >
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
> >
> >
> -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux
> > Tutorials
> > Free Linux tutorial presented by Daniel Robbins,
> > President and CEO of
> > GenToo technologies. Learn everything from
> > fundamentals to system
> >
> administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE:
> > http://www23.brinkster.com/noicys/devcpp/ub.htm
> >
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Photos: High-quality 4x6 digital prints for 25=A2
> http://photos.yahoo.com/ph/print_splash
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Paul I. <pi...@ot...> - 2004-04-20 14:06:37
|
Citerar Per Westermark <pw...@ia...>: > Actually, depending on OS the array is _sometimes_ passed by the comman= d > shell but for a lot of OS, the application just receives a text line a= nd > must itself split it into arguments. You mean parsed by the command shell, not passed. (well anyhow it is then= =20 passed)... /Paul |
|
From: <gl...@gr...> - 2004-04-20 20:10:19
|
So, you can choose yourself the way you pass the arguments to the applications becouse you are going to write the shell code |
|
From: Daniel K. O. <dan...@ya...> - 2004-04-20 09:40:33
|
Alain Paschoud wrote:
>The loop is like :
>
>while (!EOF) {
> fread(&mycharbuffer, 1, 1, myfile);
>}
>
>How can I read a file so that every byte can be any value between 0x00 and 0xFF in this file ???
>
>
This is known as "the Pascal disease".
http://www.eskimo.com/~scs/C-faq/q12.2.html
I would recomend you to a tutorial that explains what functions are (EOF
is not a function) and how to do I/O in C.
http://www.geocities.com/tom_torfs/cintro.html
Daniel K. O.
|