Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:38:49+00:00 2026-06-17T08:38:49+00:00

int main () { char str[] =kk,12,,23,4,,,3434,3,33,,,; char * valarr; int count=0; valarr =

  • 0
 int main ()
 {

    char str[] ="kk,12,,23,4,,,3434,3,33,,,";
    char * valarr;
    int count=0;
    valarr = strtok(str,","); 
    while(valarr != '\0')
    {
               valarr = strtok(NULL,","); 
    count++;
    }
    printf("%d\n",count);
   return 0;
  }

In above program the output is 7.

It seems that the strtok is tokenizing consecutive commas at once.

Instead of consecutive commas I can introduce a blank in between but
Is there a way to overcome this so that I have empty space also in the count ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:38:50+00:00Added an answer on June 17, 2026 at 8:38 am

    Correct. The documentation states this pretty clearly:

    A sequence of two or more contiguous delimiter characters in the parsed string is considered to be a single delimiter.

    That’s just how strtok() is supposed to work. You might be better of rolling your own, which will also free you from strtok()‘s nastiness.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> int main() { char str[25] = helloworld; printf(%s %s, &str+2,str+2); return 0; }
While running following code, my program crashes unexpectedly! #include<stdio.h> #include<string.h> int main(){ char *str
int main() { char *p,c; for(p=Hello World;c=*p;++p) { printf(%c,c); } } In the above
#include <stdio.h> int main() { char str[11] = HelloWorld; printf(%s\n,str); printf(%s\n,str+3); /* This Line
#include<stdio.h> int main() { int i,n=0; char str[]=karthik; while(*(str+n)!='0') n++; for(i=0;i<n/2;i++) {char temp=str[i]; str[i]=str[n-i-1];str[n-i-1]=temp;
Here is my code: void reverseStr(char *str) { if (str == NULL) return; int
int main( ) { char str[200]; int n,tc; scanf(%d,&tc); while(tc--) { scanf(%d,&n); gets(str); puts(str);
Why this code does not work? int main(){ char *str =abcde; scanf(%s,str); printf(%s,str); }
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
Here's my program so far: int main() { char choice = 'D'; string inputString;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.