strtok() needs to be able to modify the buffer it's scanning. As declared, you cannot modify cmd (which sub_cmd references). Use an array instead of a pointer declaration.
Thanks Alister!
But i checked the strtok syntax shows: char * strtok ( char * str, const char * delimiters );
This was a sample program i was trying. In the original code, the cmd is actually passed to a function from elsewhere as const char* which i've done strdup to get char*.
So is there a way to do this by keeping cmd as char*?
any alternate way...
Last edited by ashwini.engr07; 10-15-2011 at 10:53 PM..
Thanks Alister!
But i checked the strtok syntax shows: char * strtok ( char * str, const char * delimiters );
It's the memory that's important, not the labels. Unwritable remains unwritable memory even after you force a 'const char *' pointer into 'char *'. Which is what you are doing by putting "strings" into 'char *' variables, incidentally.
A "string" like that is a const char *, even though you're shoving it into a "char *" pointer.
Quote:
This was a sample program i was trying. In the original code, the cmd is actually passed to a function from elsewhere as const char* which i've done strdup to get char*.
So is there a way to do this by keeping cmd as char*?
You've not done strdup() here, and are trying to modify the original "string" which resides in read-only memory.
Again, 'char *' is just a label. Putting a "string" inside a "char *" does not make it modifiable.
You'll just have to make a duplicate, either with strdup() or by saving into your own local buffer.
Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1...
I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one.
Below are two very condensed snippets of which I have added the results inside the each code section.
IMPORTANT!... (11 Replies)
I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me.
For example this code
#include <stdio.h>
main()
{
unsigned long a=0;
unsigned long b=0;
int z;
{
printf("Enter two... (2 Replies)
Hi Guys,
I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error:
"Segmentation fault"
Can someone please help me resolve this?
Thanks alot (2 Replies)
this is a network programming code to run a rock paper scissors in a client and server.
I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault.
-the segmentation fault is fixed
Current problem -Also... (3 Replies)
I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this :
i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Hi,
I am having this segmentation fault not in the following program, bt. in my lab program . My lab program is horrible long so cannot post it here bt. I am using the following logic in my program which is giving the segmentation fault. Bt. if I run this sample program as it is it dosen't give... (3 Replies)
Hi ,
During execution a backup binary i get following error
"Program error 11 (Segmentation fault), saving core file in '/usr/datatools"
Riyaz (2 Replies)
hello all,
I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element.
... (3 Replies)