I/o C

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 63
Reputation: rowly is an unknown quantity at this point 
Solved Threads: 3
rowly's Avatar
rowly rowly is offline Offline
Junior Poster in Training

I/o C

 
0
  #1
Apr 7th, 2007
Hey guyz, I'm stuck with this given, its bit hard I cant understand it just wonna know the logic ( no codes).

Its saying write a C program which read from standard input, replaces all the occurrences of the characters by the first command line argument, with the corresponding characters supplied by the second command line argument, and writes the output to a file supplied by the 3rd command line argument, then print out the file.
NB:
1- you should attempt to read in blocks of charz, change these blocks and write them to file rather than read on char at a time
2- if the 1st number of characters in the first argument are different then the number of chars in the second argument, its up to you how to handle this situation.
DarkCoder+
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: I/o C

 
0
  #2
Apr 7th, 2007
Say for example your program name is replace.exe. Then you call that program with three command line options.
Example.

replace.exe abc def outputfile.txt

Then the program will read user input line by line and write the output to outputfile.txt.

e.g
           input                           output
            abab                            dede
            a                               d
            abracadabra                     derdfddderd
I think the NB part is simple to understand. If you dont please say.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 63
Reputation: rowly is an unknown quantity at this point 
Solved Threads: 3
rowly's Avatar
rowly rowly is offline Offline
Junior Poster in Training

Re: I/o C

 
0
  #3
Apr 7th, 2007
Originally Posted by WolfPack View Post
Say for example your program name is replace.exe. Then you call that program with three command line options.
Example.

replace.exe abc def outputfile.txt

Then the program will read user input line by line and write the output to outputfile.txt.

e.g
           input                        output
            abab                            dede
            a                               d
            abracadabra                     derdfddderd
I think the NB part is simple to understand. If you dont please say.
umm beauty ! it easy now and the ouptputfile.txt should contain only derdfddderd which the last output isn't ?!
1 more question is it right to read from buffer straight away?
for example
buff[200]
buff will constain the abab so i'll read the buffer and replace the characters with the second characters
Last edited by rowly; Apr 7th, 2007 at 12:55 pm.
DarkCoder+
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: I/o C

 
0
  #4
Apr 7th, 2007
Originally Posted by rowly View Post
ouptputfile.txt should contain only derdfddderd which the last output isn't ?!
It should contain all the outputs for all the inputs the user enters.
  1. dede
  2. d
  3. derdfddderd
Originally Posted by rowly View Post
1 more question is it right to read from buffer straight away?
for example
buff[200]
buff will constain the abab so i'll read the buffer and replace the characters with the second characters
If the output is correct, it doesnt matter how you do it.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 63
Reputation: rowly is an unknown quantity at this point 
Solved Threads: 3
rowly's Avatar
rowly rowly is offline Offline
Junior Poster in Training

Re: I/o C

 
0
  #5
Apr 7th, 2007
aha
ok zn i'll start with coding...
thx alote mate
DarkCoder+
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 63
Reputation: rowly is an unknown quantity at this point 
Solved Threads: 3
rowly's Avatar
rowly rowly is offline Offline
Junior Poster in Training

Re: I/o C

 
0
  #6
Apr 10th, 2007
alright guyz is that the right logic ?!
replace.exe abc def outputfile.txt

e.g

           input                        output            abab                            dede            a                               d            abracadabra                     derdfddderd
create char **temp1[1024]
then copy argv1[i] to temp1[i] so 
argv[0] = replace.exe and temp[0]= replace.exe 
argv[1]=abc  and temp1[1]=abc
argv[2]=def   and temp1[2]=def 
and zn copy temp1[i+1] to argv[i]
is this the right logic to replace them !?
DarkCoder+
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 63
Reputation: rowly is an unknown quantity at this point 
Solved Threads: 3
rowly's Avatar
rowly rowly is offline Offline
Junior Poster in Training

Re: I/o C

 
0
  #7
Apr 10th, 2007
hello guyz, is there any user input i mean like is there fgets ?!
because ./a.out abc def blabla
please enter character : jdk
bef
... ?! is this how it should go ?!
DarkCoder+
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC