LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 08-25-2005, 01:32 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
damn it...gdb and c


OKAY now i am crazy......

I have written a small prog in c .. before the program exits prints the following message
printf("Now the buffer is %s \n",buffer);


Now the buffer is line1
line2 (line 3 is blank)line4line5line6


When i use the gdb i use run and the programme ends succesfully i type
p buffer (print buffer)
and this gives me the following


(gdb) print buffer
$1 = "line1\nline2 (line 3 is blank\nline4\n\nline5\n\nline6\000\000"

as u can see my string has many \n characters but i dont know why at the first case are ignored
 
Old 08-25-2005, 10:09 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Well, it's kind of hard to say why you're getting anything without seeing your code.
 
Old 08-25-2005, 02:29 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Another question: are you really getting "\n" (a 1-byte newline character), or are you actually getting the two characters "\", followed by "n"????

Here's my test program:
Code:
#include <stdio.h>

int
main (int argc, char *argv[])
{
  char *s = "line1\nline2 (line 3 is blank\nline4\n\nline5\n\nline6)";
  return printf ("s: %s.\n", s);
}
Here's the compile and ouput:
Code:
% gcc -g -o x x.c
% ./x
s: line1
line2 (line 3 is blank
line4

line5

line6).
And here's the Gcc output (edited for clarity):
Code:
(gdb) p s
$1 = 0x8048518 "line1\nline2 (line 3 is blank\nline4\n\nline5\n\nline6)"
(gdb) x/10x s
0x8048518 :  0x656e696c      0x696c0a31      0x2032656e     0x6e696c28
0x8048528 :  0x20332065      0x62207369      0x6b6e616c     0x6e696c0a
0x8048538 :  0x0a0a3465      0x656e696c
<= YOU'LL NOTICE THE "0x0a" CHARACTERS IN THE EXPECTED PLACES...

Just a thought .. PSM
 
Old 08-25-2005, 03:01 PM   #4
Biotachyonic
LQ Newbie
 
Registered: Aug 2005
Location: Oklahoma
Posts: 15

Rep: Reputation: 0
Looks like it worked perfectly. Not understand what your problem is. I'm sure you know that when you printf s it is going to print on the same line until there is a \n(newline), then it's going to go down a row, and go on printing till the next \n.
 
Old 08-26-2005, 01:55 PM   #5
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Yea im a little confused on exactly what your problem is here too. Looks like the computer did exactly
what you told it to do.

???
 
Old 08-26-2005, 03:16 PM   #6
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
i think his problem is that he es expecting his output to look like:

line1
line2
(line 3 is blank)
line4
line5
line6

but he's getting it all spit out onto two lines.

is that right?

what do you get if you do:

printf("Now the buffer is \n");
printf(buffer);
 
Old 08-26-2005, 04:25 PM   #7
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Rep: Reputation: 32


shouldnt he need a " afer each \n??? i thought in C you had to have many " if all on one line in source code?

Code:
$1 = "line1\nline2 (line 3 is blank\nline4\n\nline5\n\nline6\000\000"

Last edited by boxerboy; 08-26-2005 at 04:26 PM.
 
  


Reply



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
normal gdb and spec gdb for kgdb Igor007 Programming 1 09-23-2005 04:15 PM
normal gdb and spec gdb for kgdb Igor007 Linux - Newbie 1 09-23-2005 01:41 PM
gdb .. looking for 32 bit gdb.. for ia64 suse.. nkshirsagar SUSE / openSUSE 0 12-09-2004 03:02 AM
How to use GDB ? indian Programming 4 09-06-2004 05:11 AM
using the gdb varala_kanth Linux - Software 1 04-01-2004 06:49 AM

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

All times are GMT -5. The time now is 08:33 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
Open Source Consulting | Domain Registration