본문 바로가기
dev/C

[C] function - strtok()

by seohan1010 2024. 5. 29.

STRing TOKenize

 

 

 

https://pythontutor.com/visualize.html#mode=edit

 

Python Tutor code visualizer: Visualize code in Python, JavaScript, C, C++, and Java

Please wait ... your code is running (up to 10 seconds) Write code in Python 3.11 [newest version, latest features not tested yet] Python 3.6 [reliable stable version, select 3.11 for newest] Java C (C17 + GNU extensions) C++ (C++20 + GNU extensions) JavaS

pythontutor.com

 

ex1)

 

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {

  char str1[30] = "this is for test";
  
  char *ptr = strtok(str1," ");
  
  while(ptr != NULL){
      
      printf("%s\n", ptr);
      ptr = strtok(NULL," ");
      
    }
  

  return 0;
}

 

 

 

 

 

ex2)

 

여러개의 기준문자를 지정할수도 있다.

'dev > C' 카테고리의 다른 글

[C] function - atoi  (0) 2024.05.29
[C] function - strrchr()  (0) 2024.05.29
[C] string - 4  (0) 2024.05.28
[C] string - 3  (0) 2024.05.27
[C] string - 2  (0) 2024.05.27