Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- int main(void)
- {
- /* khong doc duoc str khi bat dau bang dau tru (-)
- nen ta can them vao truoc no 1 ky tu nao do
- */
- char* str= "-1.223 %^& fsf 0.234 56.65 fsf 9 f";
- // khai bao, cap phat bo nho them s de cong them vao dau 1 ky tu
- char* const s = (char*)malloc(sizeof(strlen(str))+1);
- // cong them ky tu a
- strcpy(s, "a");
- strcpy(s + strlen(s), str);
- printf("%s\n",s);
- // tach lay cac so
- int total_n = 0;
- int n;
- float i; // cac so can tach
- printf("\nday cac so\n");
- while (1 == sscanf(s + total_n, "%*[^0123456789-]%f%n", &i, &n))
- {
- total_n += n;
- printf("%f\n", i);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement