Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name : Huynh Quang Thao
- * Id : SE60963
- * Description : Problem 1
- */
- #include<stdio.h>
- #include<string.h>
- int main() {
- printf("Word Counter\n");
- printf("==============\n");
- char s[100];
- char tokenizer[] = {" \t\f\n\v"};
- int count = 0;
- while (1) {
- fflush(stdin);
- memset(s,0,sizeof(s));
- count = 0;
- printf("String to be counted:\n");
- scanf("%[^\n]",s);
- char * pch;
- pch = strtok(s, tokenizer);
- while (pch != NULL) {
- count++;
- pch = strtok(NULL, tokenizer);
- }
- printf("res:%d\n", count);
- }
- return 0;
- }
- /*
- * Name : Huynh Quang Thao
- * Id : SE60963
- * Description : Problem 2
- */
- #include <stdio.h>
- #include <string.h>
- int main(){
- printf("String Cleaner\n");
- printf("==============\n");
- char s[100], d[100];
- memset(d,0,sizeof(d));
- char tokenizer[] = {" \t\f\n"};
- printf("String to be cleaned:"); scanf("%[^\n]",s);
- char * pch;
- pch = strtok(s,tokenizer);
- while (pch != NULL){
- strncat(d,pch,strlen(pch));
- strncat(d," ",1);
- pch = strtok(NULL,tokenizer);
- }
- d[strlen(d)-1]='\0';
- printf("Cleaned String:%s\n",d);
- }
Advertisement
Add Comment
Please, Sign In to add comment