xFactorSchool.com
Python
JavaScript
How to Do Examples
C Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Compilers
C Compiler
C++ Compiler
C# Compiler
Java Compiler
Python Compiler
HTML Code Editor
CSS Code Editor
JavaScript Compiler
JavaScript Code Editor
Practice how to check whether string data can be converted to integer or double types in C
C Online Editor
Execute Code
More C Sample Codes
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int outputInteger; const char* stringVariable = "1225"; //string data if (sscanf(stringVariable, "%d", &outputInteger) == 1) //converting data using sscanf and checking { printf("%d\n", outputInteger + 25);//if conversion succeeds } else { printf("%s cannot be converted to an integer.\n", stringVariable);//if conversion fails } double outputDouble; const char* stringNewVariable = "1225.25";//stirng data if (sscanf(stringNewVariable, "%lf", &outputDouble) == 1) //converting data and checking { printf("%f\n", outputDouble + 12.46);//if conversion succeeds } else { printf("%s cannot be converted to a decimal.\n", stringNewVariable); //if conversion fails } int outputInteger2; const char* stringVariable2 = "T1225"; if (sscanf(stringVariable2, "%d", &outputInteger2) == 1) //converting data and checking { printf("%d\n", outputInteger2 + 25);//if conversion succeeds } else { printf("%s cannot be converted to an integer.\n", stringVariable2); //if conversion fails } return 0; }