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

  • Home
  • SEARCH
  • 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 786473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:02:49+00:00 2026-05-14T21:02:49+00:00

Its been a while now and im still trying to get a certain code

  • 0

Its been a while now and im still trying to get a certain code to work. I asked some question about different commands etc. before, but now I hope this is the final one (combining all questions in one code).

I basically want to :

*Scan an input (should be character ? )

*Check if its a number

*If not, return error

*Convert that character into a float number

*Copy the value to another variable ( I called it imp here)

Here is what I came up with :

EDITED CODE*

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
main(){  
  int digits;
  float imp=0;
  char* alpha;
  do{

    printf("Enter input\n\n");
    scanf("\n%c",alpha);
    digits=isdigit(alpha);
      if(digits==0){
         printf("error\n\n");
      }
     imp=atof(alpha);
  }while(digits==0);

}

The problem is this code does not work at all … It gives me that atof must be of a const char and whenever I try changing it around, it just keeps failing. I am frustrated and forced to ask here, because I believe I have tried alot and I keep failing, but I wont be relieved until I get it to work xD So I really need your help guys.

Please tell me why isnt this code working, what am I doing wrong ? I am still learning C and really appreciate your help 🙂

EDIT
Error given atm is :

Argument no 1 of 'isdigit' must be of type 'const int', not '<ptr>char'

EDIT
This code compiles fine, but crashes when an input is entered.

  #include<stdio.h>
  #include<stdlib.h>
  #include<ctype.h>
  main(){  
  int digits;
  float imp=0;
  char* alpha=0;
  do{

   printf("Enter input\n\n");
   scanf("\n%s",alpha);
   digits=(isdigit(alpha[0]));
   imp=atof(alpha);
  }while(digits==0);
 }
  • 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-05-14T21:02:50+00:00Added an answer on May 14, 2026 at 9:02 pm

    Why not have scanf do the atof conversion for you?

     #include <stdio.h>
     int main()
     {  
        float imp=0;
        while (1)
        {
           printf("Enter input\n\n");
           if (scanf("%f", &imp) < 1) break;
        }
        return 0;
    }
    

    Your most recent example is failing because alpha is a NULL pointer. Declare it as char alpha[40]; to allocate space for it. You’ll probably want to use %40s in your format string to prevent scanf from overflowing alpha.

    Also, use strtod instead of atof and you’ll know whether the conversion was successful (better than your method of using isdigit which will fail on a negative integer).

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

Sidebar

Ask A Question

Stats

  • Questions 400k
  • Answers 400k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It turns out the value actually was zero. The hosting… May 15, 2026 at 4:05 am
  • Editorial Team
    Editorial Team added an answer Use sessions: https://docs.djangoproject.com/en/1.8/topics/http/sessions/ And then do something like: def my_view(request,… May 15, 2026 at 4:05 am
  • Editorial Team
    Editorial Team added an answer Indent: Alt+Tab Un-Indent: Shift+Alt+Tab May 15, 2026 at 4:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.