String manipulation

why everythime I try to use a function from <string.h> (strcat, strcpy, ecc) at runtime it gives me the memory fault error?
I alway use the strings (as char* or char[]) without problems.

I know how to work with strings in C/C++, so I think is some characteristic of QNX

Well you may think you know how to work with strings but apparently you don’t. Can you post some code.

Trust me. you can say I’m not competent with QNX and you are right, but if I say that I know how to work it, it’s true!

however, I solved my problem. I still think qnx manage memory in a way that I’ve not learn yet, but I found a different way to do it…

Sorry don’t want to sound rude or anything, but strings are strings and their behavior is defined by the C language and NOT by the operating system. Of course if you store them in shared memory or use IPC to transfert them, that’s a different issue, which is not string specific.

It’s the first time in 15 years that I hear somebody say that something is wrong with string operation in QNX. Given how many people use string on a daily basis in QNX I very much doubt there is something wrong with them. It must be your understanding or your expectation that are off.

Please post some of your code, that will put all doubt aside.

yes, probabilly I’m the worst when I try to explain myself…eheh

so, I know that problems with strings are not from the O.S… I try to explain what’s inside my head but I think you will miss everything (me dog, I can just bark and scratch some code :smiley:)

however I solved my original problem…now I’ve got another problem but the code is very long.

I must read some strings.
made other strings using strcat() in a particular way.
log everything in a file.

very simple, I know.
everything is a little bit harder bcause I must read the strings from 14 HW ports at the same time, but using the pthread family is not so hard.

to not lose (???) infos, I store all the things read, in a queue, which is in a thread and simply take strings (when it make sense) and put into a file.

now, when I extract the first element from the queue to log into the file, I see that it is not the same I put inside…or better, the second part is right, the first not (e.g. “/dev/ser1 - message 1” → “/devHç1°5°- Message 1”)

this is done:
(I miss everything not very very important)

[code]char* msg = “a random message”
char* dev = “/dev/ser1”;
char* newmsg;

strcpy (newmsg, dev);
strcat (newmsg, " - ");
strcpy (newmsg, msg);

the queue is a class so it’s more easy to control.

class coda { char* msg[80]; //where incoming messages are stored };

int coda::Insert(message) { strcpy(msg[index], message); //where index is the firs free location in the queue }

the remove functin is

char* coda::Remove(){ char* message = msg[index]; //some IF msg[index] = NULL; }

(everywhere is needded there are some IFs to prevent errors.)
write this, I think there aren’t particular problems but it is not true at all…

probabilly You don’t have understand nothing of what I sayd!! If i write in a too wrong english don’t waste time in replys…


P.S. You have 15 years of experience…I’m just 20… :wink:

I’m assuming you are missing some stuff, because the first strcpy will sigsegv…

char *newmsg is just a pointer, there is no room to hold the string. In this example newmsg is not even initialise, so the string is being copied to a random location

This also will sigsegv… char *msg[80] doesn’t define room for 80 string, it defines 80 pointers to a string. After a remove msg[index] is equal to NULL, so if you do an insert after you will try to copy a string at the address NULL.

Doesn’t mean I could be wrong :wink:

There also seems to be a bit of misunderstanding.

char *dev = “/dev/ser1”;

Even if newmsg is allocated properly, will not copy charactor from the device /dev/ser1.
You might want to look at open(), fopen(), and maybe getc() for starters.