more problems with my C program

Thread Tools Search this Thread
Top Forums Programming more problems with my C program
# 1  
Old 04-18-2002
Question more problems with my C program

I've run into 2 problems now, the first problem is probably a simple one it is in reguards to the argv[] pointer
I have an if statement as follows:

if(argv[1] == "-l")

but when I compile the program and type in
a.out -l
the if statement is not shown
what do I need to do to get this if statement working.

the second problem is I have a while loop that displays text via printf and then I use a gets to take in a string. I need the loop to be only broken when ctrl-d is pressed. I have NO idea of how to do this Smilie
if anyone has an idea let me know.
# 2  
Old 04-18-2002
take a look...

at some code that I wrote for should help u a lil with your arg prob.
# 3  
Old 04-18-2002
take a look...

at some code that I wrote for should help u a lil with your arg prob.
# 4  
Old 04-18-2002
for the second, try inserting

if ( EOF ) break;

Previously the end of the loop.
# 5  
Old 04-18-2002
thankyou heeps jj1814, my modified if statement now looks like this and it works: Smilie Smilie

if((argv[1] !=NULL) && (strcmp(argv[1], "-l") == 0))

here is the basic while loop that I'm working with that I need the Ctrl-d to exit from

while (1 == 1)
lDay = ptr->tm_mday;
lMonth = ptr->tm_mon + 1;
lYear = ptr->tm_year + 1900;
lHour = ptr->tm_hour;
lMinute = ptr->tm_min;

printf("%u/%u/%u|%u:%u>> ",lDay, lMonth, lYear, lHour, lMinute);
fprintf(theDatafile,"%u/%u/%u|%u:%u|%s\n",lDay, lMonth, lYear, lHour, lMinute, &strDescription);
printf("\nTask Added:\t\"%s\"\n", &strDescription);

what would I use to get ctrl-d to exit that loop, and where would I use it (exactly) it really has to be around the gets() section, cause that is where the user is prompted for input.

Last edited by Pyro-San; 04-19-2002 at 12:37 AM..
# 6  
Old 04-19-2002
The instruction to interrupt a loop is break

you can do something like

printf ("You want to continue? \n");
if ( getc() == 's' ) {break }
else {continue};

or similar the important is the break instruction or a false return
between ( )

while ( TRUE ) or while ( 1 ) is equal a while ( 1 == 1 )

try also

printf ("You want to continue? \n");
while ( getc() == 's' )

And it proves gives to be writing programs in your computer several up-to-date minutes. It is also useful to use man pages.
# 7  
Old 04-20-2002
no that is not what I want to do Smilie
what I want is the stty (tty) explained how it is used really, cause I need to 'remap' the ^d (Ctrl-d) to exit the while loop.
so if anyone can explain the use of stty for me I would be most greatfull
by explination I would be happy with a small program that does this on it's own so I can see it in action.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies

2. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

3. Programming

Python program faster than C++ program.

I wrote a simple program that generates a random word 10,000,000 times. I wrote it in python, then in C++ and compared the two completion times. The python script was faster! Is that normal? Why would the python script be faster? I was under the impression that C++ was faster. What are some of... (2 Replies)
Discussion started by: cbreiny
2 Replies

4. Programming

Problems compiling OpenStep program.

I use Ubuntu 10.4, and I installed GNUStep, Gorm (a gui builder) and ProjectCenter (the GNU alternative to Xcode) because I want to develop Objective-C apps. I opened the ProjectCenter and I created an application that displays only an empty window. I sourced the and I compiled the app. ... (0 Replies)
Discussion started by: mghis
0 Replies

5. Shell Programming and Scripting

Problems in Program Day of Week

My problem is that i want to calculate the day of the week, i want to change result given as a number for the day. I mean, the program now do that if the day is Monday is represented by 0, Tuesday by 1.. but i want the word "Monday" as a result. I thought in a bucle if but there is always a... (3 Replies)
Discussion started by: mik4us
3 Replies

6. Programming

Problems while linking Fortran program (-> undefined reference to...)

Hello, we are a group of students (mechanical engineering) who are trying to port UNIX-software to a PC Linux system during a study project. The first goals were achieved: compiling the Fortran code and creating object files. However, we encounter errors during the linking process. This is... (0 Replies)
Discussion started by: Dynamo
0 Replies

7. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

8. UNIX for Dummies Questions & Answers

Problems installing a program through Terminal in Mac OS X

Hey all.. I have a problem with the BitTorrent client called Deluge. (Deluge BitTorrent Client). Followed the guide on their homepage, but can't get it to work. First of all I have installed Xcode Tools 3.0 and MacPorts. I did the "sudo port install deluge" command, and all packages seemed to... (1 Reply)
Discussion started by: Sixmax
1 Replies

9. Shell Programming and Scripting

Problems installing a program in Terminal

Hey First of all: I'm on a Mac. I'm quite new to this, so forgive me if i sound like a newb :-) I wish to install the Deluge BitTorrent client. First of all I installed Macports and made it run smooth. But then I ran into a problem when I should install Deluge. I can post the log, and maybe... (4 Replies)
Discussion started by: Sixmax
4 Replies

10. UNIX for Advanced & Expert Users

Program/ Memory Problems

I need some advise. I have an application server running several applications. When I try and start a particular application when the others are running I receive the following. This is appearing in the core file that is created. ... (1 Reply)
Discussion started by: dbrundrett
1 Replies
Login or Register to Ask a Question