LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 46

Quote:
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:

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

Original Poster
Rep: Reputation: 0
Quote:
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, 12:01 AM   #18
paulsm4
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:

http://www.microsoft.com/exPress/

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

IMHO .. PSM

PS:
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 12:03 AM.
 
Old 01-25-2010, 06:22 AM   #19
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 402

Rep: Reputation: 51
Quote:
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, 09:13 AM   #20
johnsfine
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, 09:16 AM   #21
Xyro
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, 02:12 AM   #22
shishir
Member
 
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 12:33 AM.
 
  


Reply


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 09:36 PM
converting char to unsigned integer in c mohtasham1983 Programming 2 02-27-2007 02:58 PM
C++ converting from char to integer MicahCarrick Programming 4 12-19-2005 02:16 PM
Convert Integer to Char gjagadish Programming 5 10-14-2005 10:09 AM
Comparing Char arrays n_ick2000 Programming 5 02-25-2003 09:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 PM.

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