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
redirection DNAx86 Shell Programming and Scripting 9 04-18-2008 11:24 AM
sed redirection myle UNIX for Dummies Questions & Answers 3 03-12-2008 04:04 PM
csh stderr redirection jolok Shell Programming and Scripting 0 04-15-2005 07:03 AM
I/O redirection within a coprocess Mugin Shell Programming and Scripting 4 10-21-2003 05:17 AM
redirection to tty** with cat zorro UNIX for Dummies Questions & Answers 1 11-02-2001 08:23 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 12-11-2001
Registered User
 

Join Date: Dec 2001
Posts: 1
Question Help with redirection

Here is my problem. I don't know make this redirection thing work. The output file (called output.c) looks like this

#include<stdio.h>

int main()
{
int k;
int m;

print f("%d\n", k);
printf("%d\n", m);

return 0;
}

the input file(called input.c) is this
#include<stdio.h>

int main()
{
int k;
int m;

k=5;
m=4;

return 0;
}

I then compile the output file and do
a.out&lt;input

and it does not print 5 and 4, it prints some jumble of numbers.
Please help!
Shallon1
Reply With Quote
Forum Sponsor
  #2  
Old 12-11-2001
auswipe's Avatar
Registered User
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 536
Quote:
Here is my problem. I don't know make this redirection thing work. The output file (called output.c) looks like this

#include

int main()
{
int k;
int m;

print f("%d\n", k);
printf("%d\n", m);

return 0;
}
The reason that you are getting a bunch of numbers is that the int vars k and m are never assigned a value. You are displaying the values of what is in the memory address of k and in the memory address of m at the time of execution. The contents of an unassigned variable at execution time is commonly referred to as "compilter garbage".
__________________
Not quite as cool as all the other Kids...
Reply With Quote
  #3  
Old 12-12-2001
shaik786
Guest
 

Posts: n/a
Hi!

What exactly are you trying to do???
From what I've understood, you are trying to pass the values 5 and 4 from the file input to the file output. If this is what you are trying to do, your files should look like:

input:
======
5
4

output.c
=======
#include < stdio.h >

int main()
{
int k;
int m;

scanf("%d", &k);
scanf("%d", &m);

printf(" %d, %d\n", k, m);

return 0;
}

ofcourse, you can go about with your C Programs also by modifying your input.c file to "printf()" 'k' and 'm' and your output.c should be like the code pasted above, but you'll have to use pipes:
input | output

and just one more thing, check your uninitialized variables!!!

Regards
SHAIK

Last edited by shaik786; 12-12-2001 at 05:00 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0