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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:53:11+00:00 2026-06-13T10:53:11+00:00

This is my code: char str[] =; scanf(%s,&str); char * pch; pch = strtok

  • 0

This is my code:

char str[] ="";
scanf("%s",&str);
char * pch;
pch = strtok (str,"#");
printf ("%s\n",pch);
return 0;

I need to render an input of “1#2#3” to three integers first, second and third.
My code above tackles only the first variable and prints the first string “1” but i want to save it to an int variable.

I tried:

int first = atoi(&pch)

But ‘first’ get’s the value 0 instead of 1. How can i parse a pointer of an array char to int?

  • 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-13T10:53:12+00:00Added an answer on June 13, 2026 at 10:53 am

    If you know the precise layout of the input, and the exact number of ints, you can simplify this greatly:

    scanf("%d#%d#%d", &a, &b, &c);
    

    Here is a link to a demo on ideone.

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

Sidebar

Related Questions

Why this code does not work? int main(){ char *str =abcde; scanf(%s,str); printf(%s,str); }
Does this code have defined behaviour? char *str = NULL; printf(%s\n,str); In context of
Consider this code: const char* someFun() { // ... some stuff return Some text!!
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
I have this snippet of the code char *str = 123; if(str[0] == 1)
This code is giving me a segmentation fault at run time. char *str =
I have this code: void changeToCapital(char* str) { int i; for (i=0; i<strlen(str); i++)
Now i have this code, but it always set null UNICODE_STRING str; char *cmp
int main( ) { char str[200]; int n,tc; scanf(%d,&tc); while(tc--) { scanf(%d,&n); gets(str); puts(str);
So this code has the off-by-one error: void foo (const char * str) {

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.