I'm tracking down a stupid computer bug. I'm just sort of curious why
'/0' string won't show up after I add it. Here is the code snippet
void *allocate_string_array(size_t len, char *line, char **strarr)
{
int count = 0;
if( (len+1) < MAXLINE) {
if((strarr=malloc(sizeof(line) + 1)) == NULL){
return NULL;
}
strarr[count] = dupstr(line);
}
else {
fprintf(stderr, "Input line is too long \n");
exit(EXIT_FAILURE);
}
*(strarr+len+1)='\0';
return *strarr;
}
When I first enter the function
(gdb) print *strarr
$4 = 0x0
(gdb) print line
$5 = 0x804a180 "this is a really long long line\n"
Right after I leave the function
(gdb) step
120 return *strarr;
(gdb) print line
$6 = 0x804a180 "this is a really long long line\n"
(gdb) print *strarr
$7 = 0x840a180 "this is a really long long line\n"
(gdb)
My brain doesn't always function correctly after I've worked 14 hours.
Code:
if((strarr=malloc(sizeof(line) + 1)) == NULL)
should have been
Code:
if((strarr=malloc(strlen(line) + 1)) == NULL)
However, my compiler didn't bitch about the typo. Here is what happens when I turn on full warnings.
[cda@localhost ~]$ gcc -g -Wall -ansi -Werror -pedantic x_tty.c -o x_tty
[cda@localhost ~]$
Now what does
What is "*(strarr+len+1)='\0';" trying to do?
It's just any ugly hack because I was getting some funky output. I figured the reason why I was getting funky stuff was because my string wasn't terminated. However, it only works half the time. I still somethines get
now
is a really long long line
Last edited by frequency8; 06-21-2007 at 01:16 AM..
Just got penalised for not performing a feature that didnt work for me.
I tried to edit the post twice to add code tags, both manually and via button did not work.
code - manual
code - button (7 Replies)
I am trying to print out two fields in a file using awk. So, I have got
awk -F '\t' 'NF = 2 {print $1 $2 "]"}' two.txt
in a script called what.awk
When i run this version like this - ./what.awk then it runs however I want to run the program like this
awk -f what.awk two.txt.
When I... (8 Replies)
Hi Guys,
I have a strange problem.( AIX 6.1) "vi" is not working at all..Whenever i #vi <anythin> ,, it returns the prompt back. Any clues folks?? (14 Replies)
GNU insight debugger is not available now a days and it is required to debug/inspect
assembly code as written in the book Assembly Language Programming step by step in Linux so my question is; is there any alternative to insight that I can use instead of insight in which I can get the same... (5 Replies)
this is my file I have written.
// My first C++ program
#include <iostream>
int main()
{
std::cout << "Hi there!" << std::endl";
std::cout << "This is my first C++ program" << std::endl";
return(0);
}
This is the error I get, why?
$ g++ first.cpp
ksh: g++: not found (1 Reply)
It just does the break...even though the files are not the same...
# Compare extracts
#==========================================
count=0
while (( count < 5 ))
do
(( count+=1 ))
echo "Try $count"
file1=$(ls -l /tmp/psjava.xml|... (5 Replies)
Hii All,
I am using openldap v2.3 on redhat El-4. When i run ldapsearch it returns all the entries. The command runs successfully. But when I run the ldapsearch with following filter option it doesnt work and immediately returns to the shell.
ldapsearch uidNumber>=2000
I've started slapd... (0 Replies)
When trying to copy a file in Solaris 8 it doesnt copy file or give a error. This worked 100% until the 29th. I've checked the rights and everything seems fine:
drwxrwxrwx 2 bmuser bmgroup 11776 Jan 3 10:32 spool
This is the file I want to copy:
-rwxrwxrwx 1 bmuser bmgroup ... (26 Replies)
hello there
when i try and compile i keep getting this error that 'error C2115: 'function' : incompatible types' on the following line of the code:
for (i = 0; i < nCommands; ++i) {
printf(" Command: \n", i);
printComStruct(com); // HERE
}
the following is my printComStruct... (0 Replies)