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 7787677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:44:46+00:00 2026-06-01T20:44:46+00:00

I have got my strtok working, but now because I am using scanf which

  • 0

I have got my strtok working, but now because I am using scanf which ends the string with NULL char my program is only grabbing one line from redirected standard in. eg.

scanf("%s" , input);
    token = strtok (input, ", \n");

    while(token != NULL){
            i += (strtol(token,0,0)); 
            token = strtok(NULL, ", \n"); 

    }

So I am trying to use functions to check if the program has reached just a NULL of a EOF (from what i understand EOF = -1 NULL = 0) but I’m having trouble getting the pointers and functions to work in my code. P.S. I know it’s crappy code, but it’s late and I’m still working on it while I wait for suggestions to point out my obvious errors that I’m missing.

int scanner();
int check_EOF();
int next_line(char *token);
int main(){

char *token, input[256];
int i = 0;


scanf("%s" , input);
    token = strtok (input, ", \n");

    if (!scanner())
        check_EOF();

printf("%d\n", i);
return 0;
}


int check_EOF(){
while(token !=EOF);
    next_line();
 }

int next_line(){
while(token != NULL){
    return 1;
else return 0;   
}

int scanner(){
while(next_line()){
        i += (strtol(token,0,0));
        token = strtok(NULL, ",")

    return 0
}

Is there an easier way that I don’t know about or am I heading in the right direction with lots of errors?

Thanks, Lachlan

  • 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-01T20:44:48+00:00Added an answer on June 1, 2026 at 8:44 pm

    From man scanf:

     The  value  EOF is returned if the end of input is reached...
    

    You just need to check the return value of scanf, not strtok. Something like:

    while(scanf("%s", input) != EOF)
       //just do it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a Qt project which I am configuring and building using CMake.
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible
We have got loads of options for php + MySQL + Apache combo... Which
I have got a python script which is creating an ODBC connection. The ODBC
I have got some code to load an assembly and get all types, which
I have got the following code from here to read an Excel file using
I have got a class which is called BaseCore which just runs all the
I have got script which generates some graphic and returns it as a result,
I have got 6 NSMutableArray(monday,tuesday...saturday) which I add to NSMutableArray "day" I doing in
I have got a 2d array called $myarray, and when I using var_dump($myarray), it

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.