Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-23-2010, 04:09 PM   #16
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46

Originally Posted by Reverse Logic View Post
1) I'm using fedora 12 64 bit. IDE: Fedora Eclipse Compiler: gcc 4.4.2
"Just in case", could you try the following:

gcc -std=c99 -pedantic -Wall -Wextra YourSourceFile.c -o test01
and then run `test01` via ./test01 and tell us if anything 'changes'?
Old 01-24-2010, 12:29 AM   #17
Reverse Logic
LQ Newbie
Registered: Jan 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Originally Posted by paulsm4 View Post

You *are* getting an infinite loop (it's easy to see where).
Hi Paul,

I knew there was an infinite loop, but to me it didn't seem like that was the issue, because I wasn't getting the same output over and over again like I've seen in previous infinite loops, and in fact an earlier infinite loop I had had in the same function.

But yes, everybody who had mentioned that said the infinite loop was the problem was absolutely right.

Would somebody be able to describe why the output did not keep printing? I'm a novice (in case it wasn't terribly obvious), and I'd like to learn as much as possible.
Old 01-25-2010, 01:01 AM   #18
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, Reverse Logic -

The best answer I can give you has already been suggested above - become familiar with a debugger (for example "gdb", among many other choices) and step through the code.

I'm a huge fan of Linux, and of Open Source. So I hate to admit it But the very best C/C++ IDE in the Known Universe is MS Visual Studio. If you're learning C, and you're not necessarily interested in conformance to all the latest/greatest/bleeding edge ANSI standards ... then you might be interested in downloading the free "Visual Studio Express" compiler for a Windows PC:

The Visual Studio debugger is *vastly* superior - and far easier to learn and use - than *anything* else I can think of.


Definitely feel free to thank some of the folks you helped you (the "thanks" button), if you wish.

Last edited by paulsm4; 01-25-2010 at 01:03 AM.
Old 01-25-2010, 07:22 AM   #19
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Rep: Reputation: 51
The Visual Studio debugger is *vastly* superior
Emm... i wouldn't say so Much better would be Olly Debugger. And, if you need a debugger, why change the whole IDE or even OS (i doubt that windows debuggers will work in WINE)?..

Anyway, for linux there are also GUI debuggers like ddd (though it seems dead) and some other, though i haven't found a good enough one (for me).
Old 01-25-2010, 10:13 AM   #20
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
What is "Olly"? I'll google it later anyway.

The best I've found on Linux is Insight. I don't think it is a good debugger, just not as bad as the others I've tried.

Visual Studio is the best debugger I know. It is a constant source of frustration. The newer versions seem to be worse than the 1998 version (but the 1998 version has no 64 bit support). But even the newer version aren't quite as flawed as the Linux debuggers I've tried. I don't understand why debuggers are generally so bad. They should not be that hard to get right.

I've only tried the free Visual Studio as a compiler. It is terrible. It seems to be intentionally sabotaged to generate really big slow binaries. I assume that is to force professionals to purchase the real Visual Studio. I don't know whether the free version's debugger differs from the professional version.
Old 01-25-2010, 10:16 AM   #21
LQ Newbie
Registered: Aug 2009
Location: Canada
Distribution: Ubuntu 9.04
Posts: 22

Rep: Reputation: 19
If you are not writing to sdterr, your program is stuck in the infinite loop, buffering the output to stdout and (likely due to the tight loop) never flushing the output. Fix the infinite loop problem and write to stderr and see what happens. Or add a fflush(stdout) after your fprintf(stdout,...) or printf().
Old 01-27-2010, 03:12 AM   #22
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
The problem with your code is that you are passing the same current index over and over again. eg. say the input is : 123\t345
there is a tab at index 3, you will need to return the index as 3 and continue parsing the string from index 4. This will remove the loop.

Of course, one way to fix this loop will be to actually replace the tabs with spaces :P, then your code will be just fine.

Currently, in your code, you are returning 3, and then passing 3 back which is a tab.

Oh, and the reason continuous prints might not be showing up on your terminal non-stop might be because of the terminal you are using. I used xterm and it kept dumping. I did not see much (or saw nothing till i pressed CTRL-C) on 'konsole', but after waiting a bit (perhaps due to filling up of buffers, as pointed out by many, what with stdout being fully buffered). Although, a '\n' should fix that buffering issue.

Last edited by shishir; 01-28-2010 at 01:33 AM.


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
c++ problem setting "const char *str" from function returning a string ocularb0b Programming 3 03-04-2008 10:36 PM
converting char to unsigned integer in c mohtasham1983 Programming 2 02-27-2007 03:58 PM
C++ converting from char to integer MicahCarrick Programming 4 12-19-2005 03:16 PM
Convert Integer to Char gjagadish Programming 5 10-14-2005 11:09 AM
Comparing Char arrays n_ick2000 Programming 5 02-25-2003 10:02 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 PM.

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