//I used strtok() like this:
fgets(userCommand, MAX_COMMAND_SIZE, stdin);
g_UserCommands[0] = strtok(command, " ");
while(g_UserCommands[i] != NULL){
i+=1;
g_UserCommands[i] = strtok(NULL, " ");
}
//Now I want to use strcmp() like this:
if(strcmp(g_UserCommands[0], "script")==0){
return (executeScript(arg1));
}
/* Unfortuantely, I'm not getting desired results, probably because
the strings in g_UserCommands are not null terminated. Any suggestions
on a better way to get null terminated strings in g_UserCommands or
suggestions in general? I was hoping for a function that does what
strtok() does, but also providing null termination.
Thanks!
*/ 3 2889
ern wrote: //I used strtok() like this:
fgets(userCommand, MAX_COMMAND_SIZE, stdin); g_UserCommands[0] = strtok(command, " "); while(g_UserCommands[i] != NULL){ i+=1; g_UserCommands[i] = strtok(NULL, " "); }
//Now I want to use strcmp() like this:
if(strcmp(g_UserCommands[0], "script")==0){ return (executeScript(arg1)); }
/* Unfortuantely, I'm not getting desired results, probably because the strings in g_UserCommands are not null terminated. Any suggestions on a better way to get null terminated strings in g_UserCommands or suggestions in general? I was hoping for a function that does what strtok() does, but also providing null termination.
Thanks! */
Is that the real code? If so, you are reading into the
userCommand variable and strtoking the command variable. Can
you show a complete small compilable program that shows
your problem?
strtok does terminate the strings, that is not your problem.
-David
Replace below by a strcpy between source and destination and then you
will see the intended results
g_UserCommands[i] = strtok(NULL, " ");
-Ganesh ga**********@gmail.com wrote: Replace below by a strcpy between source and destination and then you will see the intended results
g_UserCommands[i] = strtok(NULL, " ");
See sig below
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: collinm |
last post by:
hi
this is my code to analyse a file
void analyzeFilename()
{
char string="B_L2_HLD_GRN_NOR_Run_Counter.txt";
char *tokenptr;
char *seperators="_";
|
by: bubunia2000 |
last post by:
Hi all,
I heard that strtok is not thread safe. So I want to write a
sample program which will tokenize string without using strtok.
Can I get a sample source code for the same.
For exp:...
|
by: hu |
last post by:
hi, everybody!
I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0.
Program is simple, but mistake is confusing. First, the below code can get
right outcome:"ello world, hello...
|
by: spibou |
last post by:
What is strcmp supposed to return if one or both arguments passed to it
are NULL ?
|
by: Mr John FO Evans |
last post by:
I cam across an interesting limitation to the use of strtok.
I have two strings on which I want strtok to operate.
However since strtok has only one memory of the residual string I must
complete...
|
by: ohaqqi |
last post by:
Hi everybody. I haven't programmed anything in about 8 years, I've read up a little bit on C and need to write a shell in C. I want to use strtok() to take an input from a user and parse it into the...
|
by: ohaqqi |
last post by:
Hi guys,
I'm still working on my shell. I'm trying to implement a function typefile that will take a command line input as follows:
> type <file1>
This command will implement a catenation of...
|
by: Neel |
last post by:
Hi friends,
'm getting weird output with strcmp function.
'm unable to detect the error.
code is:
string myline="";
line=myline.c_str();
line='\0';
|
by: spiralfire |
last post by:
I wrote a translator, that reads a DIMACS graph format and writes to a simpler format...
basically DIMACS format is:
c comment
p type nodes edges //type is alwats edge on my problems,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |