[C / C ]The function strtok cut strings – function strtok in string
The function strtok(s1, s2) returns after the first string s1 cut by the characters in the string s2.
President s1 = “nguyen, of quan” and we use: char *p = strtok(s1,”, “) (surgical marks and spaces) p is the string: nguyen. If you want to cut to the string, we use strtok(NULL,s2) While it will cut the original string starting position that was previously stopped.
I used to do math: input 1 strings, then write that counteracts the words in the string entered (words do not contain commas, dots, how to play) and one per 1 current
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int index = 0; int i; char *a = (char *)malloc(100*sizeof(char)); char **b = (char **)malloc(100*sizeof(char));; printf ("Nhap vao chuoi can dao nguoc: "); fflush(stdin); gets(a); char *p; p = strtok(a, ",. "); //cat chuoi bang cac ky tu ,. va space while(p != NULL) { b[index] = p; index++; p = strtok(NULL, ",. "); //cat chuoi tu vi tri dung lai truoc do } for (i = index-1; i>=0; i--) //in ra cac tu theo thu tu dao nguoc printf ("\n%s ", b[i]); printf ("\n"); return 0; }
Thank you very much, I did okay.
Wish you good learning. 😀 Ghé thăm blog thường xuyên nhé.
My friend asked yourself now have a string like this
Userid:1@Name:phuong @ Password:trantuanphuong @
Userid:2@Name:Faculty @ Password:phamdangkhoa @
I had to cut it how dear. Try their usual way, but it only displays the screen user2 only
I do not know what you want to cut in but when you use 1 times it just cuts 1 time is right. You see that your code above, I have to use the loop while it cut off the chain discretion.
He related to me hoi char oi ** Is la gi values lay pointer why is not char b?
char * b, then b is 1 Chain (character array)
char ** b, this is a string array (list of strings)
Cho mình hỏi có cách nào đổi thứ tự tách của hàm strtok ko :v VD mình nhập tên Hoang Quoc Cuong nhưng mình muốn tách để in ra là Cuong Hoang Quoc :in
Cái này bạn tự đổi chỗ sau khi tách thôi vì nó tách lần lượt mà 😉
Chào Quân!
Mình có đoạn code như sau:
Khi mình chạy chương trình thì bị break. It is required to put an end to the string of characters ch.
You can help her correct code is not?
Thank you!
Sure you use C mixed C with world should be. Your review follow the example of yourselves.
Thank you! The problem lies in the variable declaration char ** yourself ch;
If your array declaration char ** ch chain so and want to use the new operator to allocate memory for it, they must write how???
You change the way their allocation in post like this is ok
Thank you very much!
If you have time, then do a tutorial on FindFirstFile function and FindNextFile nhé!
I'm having a little difficulty about this function on MSDN that read but do not understand much.
Do not know how to use it all.
Thank you,Thanks for asking you to do all you want to do :enter two search strings from appearing in both strings,and look from just appear in the string 1 not appear in the string, then how two?
I want to talk about ideas nhé,I do not know what the function as strok have no more standard libraries should not dare use
You use the stock to cut out and then browse each word in this string, compare with other word in the string is being, Your peace of mind is the function that the standard library functions.
I'm learning about dual DSLK,and have 1 standard that is: there is a list of strings of the form ngay.thang.nam
How to compare them to reorder ( firstly compare year,if five equal, month, and day to ạ)
You give me ideas vs sir. Tks him.
Right, ok so that.
Welcome!
You might ask yourself why your code yourself fix the assignment “b[index] = p” to “strcpy(b[index],p)” Thus, the time the error Rune?
I also do not know but its assignation is assigned the address of the cursor, order your copy just copy the value. So maybe it apologize for it. But you need to see it exactly in line fault yet know đk.
A cho e hỏi, ví dụ mình nhập:
you , yeu . Em, mat. Roi !
then it appears on-screen when the k , .
He pointed me how DC output k?? I would like to thank!
You use strtok cut to the characters you do not want to make. Then put together is đk
Ban asked his oi yourself visual studio solution 2015 when using strtok it unsafe for a way to not notice you
Ah can customize their in VS and eliminate some functions. You try searching google view
Thank you very much