The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Carreer:Networking Programming in Unix (C programming Language) vibhory2j UNIX for Dummies Questions & Answers 5 09-05-2008 08:57 PM
What Makes a Programming Language Successful? iBot Complex Event Processing RSS News 0 05-29-2008 06:40 PM
The Blue Programming Language 1.5.1 (Default branch) iBot Software Releases - RSS News 0 03-21-2008 08:40 PM
Qore Programming Language 0.6.2.3 (Default branch) iBot Software Releases - RSS News 0 02-11-2008 01:10 AM
Does the programming language matters? HOUSCOUS UNIX for Dummies Questions & Answers 8 02-21-2002 02:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-14-2007
convenientstore convenientstore is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 42
c programming language

Can someone enligten me on what below program does?
I understand getchar and putchar.. but what is this program suppose to do?
I try to put printf on it, but it shows nothing..

can someone explain to me what this program is suppose to do?
It is reading something and assigning to c?

so, if I do, ./a.out filename , will it assign entire filename's content into c?

#include <stdio.h>

/* copy input to output; 1st version */

main()
{
int c;

c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
}
  #2 (permalink)  
Old 05-15-2007
Raghuram.P Raghuram.P is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 44
Hi,
The program basiaclly copies the character entered by the user to the variable c and then rits it to the output.
This goes on until the user enters the EOF character(I am not sure abt the character)

Thanks
Raghuram
  #3 (permalink)  
Old 05-15-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
You would need to do:
./a.out < input.file > output.file
to run it.
  #4 (permalink)  
Old 05-15-2007
aobai aobai is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 19
do it like this
./a.out</etc/apt/source.list

and you will see it.
good luck
  #5 (permalink)  
Old 05-15-2007
aobai aobai is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 19
Quote:
Originally Posted by Raghuram.P
Hi,
The program basiaclly copies the character entered by the user to the variable c and then rits it to the output.
This goes on until the user enters the EOF character(I am not sure abt the character)

Thanks
Raghuram
EOF character

ctrl^D
  #6 (permalink)  
Old 05-15-2007
hankooknara hankooknara is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 80
I ran it like that.. and seems to work..

but what are the first character and the number?

ni32 <-- example, what is n and 32 for?


n[root@rleeserver programming_language_c]# cat > yahoo
hi
how are you
[root@rleeserver programming_language_c]# ./file_copy <yahoo
h105
ni32
n 10
n
104
nh111
no119
nw32
n 97
na114
nr101
ne32
n 121
ny111
no117
nu10
n
-1
  #7 (permalink)  
Old 05-15-2007
hankooknara hankooknara is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 80
I detected mistake in the source for n

#include <stdio.h>

/* copy input to output; 1st version */

main()
{
int c;

c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
printf("%d\n", c);
}
}

so, I took it out.. but still put number....

[root@rleeserver programming_language_c]# ./file_copy <yahoo
h105
ni32
n 10
n
104
nh111
no119
nw32
n 97
na114
nr101
ne32
n 121
ny111
no117
nu10
n
-1

Also, EOF is -1? Is there explanation of EOF anywhere on google?(let me google that too as well now).
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0