Sponsored Content
Full Discussion: better way than strtok?
Top Forums Programming better way than strtok? Post 85468 by annie on Wednesday 5th of October 2005 01:46:00 PM
Old 10-05-2005
Quote:
Originally Posted by Corona688
strchr will return the position of the first '=' in the string without having to modify the string itself.
Code:
markid=strchr(args[0],'=')+1;

It will return the "=ny" part, so incrementing it one from there will make it return the "ny" part. This assumes that the string includes '=' in it, if it doesn't it will break. But that's taken care of by prefix.
thanks!

but the catch here (which I just realized) is I need to know if they ever pass just "markid=". This means they want to clear the field....

So with the above suggestion, when they passed in "markid=", I would get NULL I assume?
 

6 More Discussions You Might Find Interesting

1. Linux

Strtok function....

can any help me out y dis program is giving me a segmentation fault..... #include<stdio.h> #include<string.h> int main() { char *str="Tanvir/home/root/hello"; const char *d ="/"; char *ret; ret=strtok(str,d); if(ret==NULL) printf("NULL NULL"); else ... (3 Replies)
Discussion started by: Tanvirk
3 Replies

2. Programming

Regardign strtok() output directing to 2-D string array

Hi, I just wrote a program in C to split a comma seperated string in to group of strings using strtok() function. The code is: int main() { char *temp;//not used here but basically we extract one string after another using strtok() and assign to a string pointer defined like this. ... (3 Replies)
Discussion started by: SankarV
3 Replies

3. Shell Programming and Scripting

strtok equivalent in perl

Hi All, Is their any equivalent for strtok (in c) to use in perl script. Thanks in advance. JS (1 Reply)
Discussion started by: jisha
1 Replies

4. Programming

How to use strtok twice in the same program?

string str1(" 1 2 3 4 512543 "); string str2; if(str2.empty()) str2=str1; cout << "str2:" <<str2 <<endl; p1=strtok((char *)str1.c_str()," "); while(p1) { ... (3 Replies)
Discussion started by: sathishkmrv
3 Replies

5. Programming

strtok with while loops

Why is line (null) after the first while loop run? (keyword does jump to the next word.) #include <ftw.h> #include <stdio.h> #include <string.h> char filenames = ""; int list(const char *name, const struct stat *status, int type) { if( (type == FTW_F) && strstr(name, ".txt") &&... (3 Replies)
Discussion started by: cyler
3 Replies

6. Programming

strtok() gives segmentation fault!!

#include<iostream.h> #include<string> #include<stdio.h> int main() { char *cmd="delete backup backup-iso image a.iso b.iso c.iso d.iso"; char *tokenized_cmd,*sub_cmd; sub_cmd=strstr(cmd,"image"); tokenized_cmd=strtok(sub_cmd," "); ... (3 Replies)
Discussion started by: ashwini.engr07
3 Replies
STRCHR(3)						     Linux Programmer's Manual							 STRCHR(3)

NAME
strchr, strrchr - locate character in string SYNOPSIS
#include <string.h> char *strchr(const char *s, int c); char *strrchr(const char *s, int c); DESCRIPTION
The strchr() function returns a pointer to the first occurrence of the character c in the string s. The strrchr() function returns a pointer to the last occurrence of the character c in the string s. Here "character" means "byte" - these functions do not work with wide or multi-byte characters. RETURN VALUE
The strchr() and strrchr() functions return a pointer to the matched character or NULL if the character is not found. CONFORMING TO
SVID 3, POSIX, BSD 4.3, ISO 9899 SEE ALSO
index(3), memchr(3), rindex(3), strpbrk(3), strsep(3), strspn(3), strstr(3), strtok(3) 1993-04-12 STRCHR(3)
All times are GMT -4. The time now is 05:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy