LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2002, 07:48 AM   #1
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,589

Rep: Reputation: 145Reputation: 145
a newbie's c++ question


Hi,
i'm trying to learn some c++ and have to write a program that copies a binary file to floppy. the book i'm learning with offers the folowing solution. but obviously it's for windows and i couldn't get it working on my box though i tried several times with various changes. everything compiled well but didn't work :-). all i get is: Exclaim: Exercise25 <file>. (anyway i don't know what that's good for.) how do i get that going? a good advice is much appreciated, thanks
jens

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

int main(int argc, char *argv[]) {
char x;
char indatei[31], outdatei[33];
if (argc<2) {
cerr <<"Exclaim: Exercise25 <file>"<<endl;
return 1;
}
strcpy(indatei, argv[1]);
strcpy(outdatei,"A:");
strcat(outdatei,indatei);
ofstream outputf(outdatei, ios:ut | ios::binary);
ifstream inputf(indatei, ios::in | ios::binary);
while (!inputf.eof()){
inputf.read(&x,1);
outputf.write(&x,1);
}
return 0;
}
 
Old 05-12-2002, 08:00 AM   #2
wwnn1
Member
 
Registered: Apr 2002
Location: PRC
Posts: 32

Rep: Reputation: 15
Wink

try below changes:

/***************************

#include<iostream.h>
#include<fstream.h>
#include<cstring.h>

***************************/

just add the ".h" as suffix.
 
Old 05-12-2002, 08:20 AM   #3
wwnn1
Member
 
Registered: Apr 2002
Location: PRC
Posts: 32

Rep: Reputation: 15
Wink

Maybe it is also because of the error of these below codes .

/*******************************
strcpy(indatei, argv[1]);
strcpy(outdatei,"A:");
strcat(outdatei,indatei);
*******************************/

just suppose that,
input the command: copy c:\file.txt

so, the string "indatei" is "c:\file.txt".
after execute the code "strcat(outdatei,indatei);"
the string "outdatei" becomes "A:\c:\file.txt".

then,when executing the code
"ofstream outputf(outdatei, iosut | ios::binary);"
the output path now is "A:\c:\file.txt".
obviously, the output path is wrong.

I am a newbie!
Maybe my advice is useless!
^_^
 
Old 05-12-2002, 10:29 AM   #4
Hano
Member
 
Registered: Sep 2001
Location: Venezuela, Caracas
Distribution: RedHat 9.0
Posts: 196

Rep: Reputation: 30
Hey! remember that in linux there's it's not an A: device, floppy its located on /mnt/floppy and has to be mounted: i don't know any functions to check that floppy is mounted, but you can always call something like:


system(" mount floppy");

which does a 'mount floppy' call from a C program, then try to open the file with a directory of type "/mnt/floppy/whatever.txt"

Hano
 
Old 05-12-2002, 01:36 PM   #5
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,589

Original Poster
Rep: Reputation: 145Reputation: 145
unfortunately the 'system("mount floppy")' does not work. (compiler takes it as an implicit declaration of function). but in general that was what my question was about: how to: mount -t /dev/fd0 /media/floppy or similar. so if someone has an idea of that - would be great. bye
jens
 
Old 05-12-2002, 01:49 PM   #6
Hano
Member
 
Registered: Sep 2001
Location: Venezuela, Caracas
Distribution: RedHat 9.0
Posts: 196

Rep: Reputation: 30
sorry! i forgot to tell you that you have to put headers on the c program:

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>


If you don't, the compiler of course doesn't know what system is

Hano
 
Old 05-12-2002, 03:19 PM   #7
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,589

Original Poster
Rep: Reputation: 145Reputation: 145
great! that seems to work. only trouble is that only 'root' is allowed to run that mount command. i guess i'll find out myself how to fix that.
muchas gracias por otra vez! and many thanks to wwnn1, naturally you were right about the name of the output file. cheers, jens
 
Old 05-13-2002, 06:50 AM   #8
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
worth remembering that "mount floppy" won't work on all systems - it would depend on there being this entry in the system's /etc/fstab:

/dev/fd0 /mnt/floppy auto ro,user,noauto 0 0

(or similar). the "user" option, btw, allows non-root users to mount the device. since this is only an example program, i guess you can change it to suite your systems fstab configuration anyway
 
Old 05-13-2002, 08:41 AM   #9
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,589

Original Poster
Rep: Reputation: 145Reputation: 145
you´re right; i actually used:
'mount /dev/fd0 /media/floppy' instead of 'mount floppy'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie's ssh and router question Normanya Linux - Networking 8 07-31-2005 10:18 PM
Another newbie's dumb question jrholl Linux - Newbie 2 04-11-2005 08:28 PM
Newbie's first trouble? wildes Slackware 13 12-21-2004 01:14 PM
Newbie's printing question - could it be more hard? shibatatie Slackware 7 10-12-2004 09:56 PM
newbie's question on how to install kernel modules Rammand Linux - Software 1 06-06-2004 09:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration