Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22199

How do I extract only the specific string I want from the string?

$
0
0

I would like to extract only /home/user01\ruuidd:x:108:114::/run/uuuidd:/usr/sbin/nologin from the code string below. What should I do?

#include <stdio.h>#include <stdlib.h>#include <string.h> int main(){    char str[1024]="\r\n\033[?2004l\r/home/user01\ruuidd:x:108:114::/run/uuidd:/usr/sbin/nologin\r\n\033[?2004h\033]0;user01@audit: ~\auser01@audit:~$ ";    char *ptr = strtok(str + 1, "\r");    strcpy(str, ptr + 1);    ptr = strtok(str, "\r\n\033");    printf("%s\n",ptr);    return 0; }

The execution result of the code I made is as follows.

root@audit:~# ./test

output : [?2004l


Viewing all articles
Browse latest Browse all 22199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>