Tags down


How can I run through all the characters of a string and check if they're all numbers in C?

By : Omar
Date : September 14 2020, 02:00 AM
this will help For starters the function read shall accept its argument by reference like
code :
void read(struct id *s);
scanf("%s", s.id_num);
void read( struct id *s )
    fgets( s->id_num, sizeof( s->id_num ), stdin );
    s->id_num[strcspn( s->id_num, "\n" )] = '\0';
int isNumber( const char p[] ) 
    const char *s = p;
    while ( isdigit( ( unsigned char )*s ) ) ++s;

    return  p[0] != '\0' && *s == '\0';
#include <stdio.h>
#include <ctype.h>

int isNumber( const char p[] ) 
    const char *s = p;
    while ( isdigit( ( unsigned char )*s ) ) ++s;

    return  p[0] != '\0' && *s == '\0';

int main(void) 
    printf( "Is a number - %s\n", isNumber( "" ) ? "true" : "false"  );
    printf( "Is a number - %s\n", isNumber( "A" ) ? "true" : "false"  );
    printf( "Is a number - %s\n", isNumber( "12A" ) ? "true" : "false"  );
    printf( "Is a number - %s\n", isNumber( "123" ) ? "true" : "false"  );

    return 0;
Is a number - false
Is a number - false
Is a number - false
Is a number - true

Share : facebook icon twitter icon

Check if string contains no characters except numbers?

By : user3078456
Date : March 29 2020, 07:55 AM
it helps some times You can use is_int
code :
$time = explode(":",$time);

if ($time['0'] > 12 || $time['0'] < 1 || !is_int($time[0]))
    //error: not valid hour
    echo("error: time val hour is bad");

Check if a string has no characters or numbers at all

By : ufser
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , In php, how can I check if a string has no characters at all.
code :
$fetch = false;

#$strFromSearchBox = 'Why-you-foo-bar-I-ought-to-tar-you';
$strFromSearchBox = 'foo-bar-tar';

if(strlen($strFromSearchBox) >=2)
    $newString = str_replace($theseWords,'',$strFromSearchBox);
    $newString = str_replace('-',' ',$newString);
    $newString=trim($newString);  //This will make the string 0 length if all are spaces
        $fetch = true;
        echo $newString;

if($fetch){echo 'True';}else{echo 'False';}

Python - Check if the last characters in a string are numbers

By : Abhi
Date : March 29 2020, 07:55 AM
I wish this helpful for you Basically I want to know how I would do this.
code :
import re
m = re.search(r'\d+$', string)
# if the string ends in digits m will be a Match object, or None otherwise.
if m is not None:
    print m.group()

Check string for numbers and characters in Oracle 11G

By : Karan Luthra
Date : March 29 2020, 07:55 AM
I wish did fix the issue. ok I'm not exactly clear on what you are doing however maybe the following might help. creating a table from data
code :
create table mytable as select 'NL 4633 4809 KTU' txt from dual;
SELECT  REGEXP_SUBSTR (txt, '[^ ]+', 1, 1)    AS part_1
,       REGEXP_SUBSTR (txt, '[^ ]+', 1, 2)    AS part_2
,       REGEXP_SUBSTR (txt, '[^ ]+', 1, 3)    AS part_3
,       REGEXP_SUBSTR (txt, '[^ ]+', 1, 4)    AS part_4
FROM    mytable;
part1 part2 part3 part4
NL 4633 4809 KTU
select REGEXP_SUBSTR (txt, '[^ ]+', 1, level) val from mytable connect by level <= regexp_count(txt,' ') + 1;

Check if string contains ONLY NUMBERS or ONLY CHARACTERS (R)

By : Z.Vula
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have these three strings: , you need to persist your regex
code :
all_num <- "123"
all_letters <- "abc"
mixed <- "123abc"

grepl("^[A-Za-z]+$", all_num, perl = T) #will be false
grepl("^[A-Za-z]+$", all_letters, perl = T) #will be true
grepl("^[A-Za-z]+$", mixed, perl=T) #will be false
Related Posts Related Posts :
  • Importance of '0' character and << operator in this program
  • How to debug a quadratic probing implementation for hash tables in C without using pointers?
  • Pointer to Pointer in c, getting unexpected value
  • "Permission denied" in open() function in C
  • How to assign an array of structs
  • Sort an Array of struct by a value of a field inside the struct
  • Implement stack with pointers in c
  • C program that goes through a string and flags for non-letters
  • C while statement in switch clause
  • Can we allocate memory for char * but return it as const char *?
  • How do Comma-separated expressions as condition in a for-loop work?
  • Sort Structs by the value of an attribute in it
  • How should I make users to put in the info that I want?
  • Are bitmask checks more efficient than comparing numbers?
  • Are the fast integer types faster when stored in the CPU registers?
  • Does realloc deallocate before trying to allocate new memory?
  • Failing to compile a 15+ year old MUD codebase written in C
  • opendir dont get content of buffer char * on C language?
  • Can we have '+' operator inside printf()?
  • Why scanf function do not accept escape sequences as an input?
  • Print strings of length of k from a and b
  • C problem with passing pointer to struct to function
  • Shall I use register class variables in modern C programs?
  • Can I specify conditions for the rand() function?
  • C fprintf and fscanf saving game state
  • Fast formula to get the range a number is in, given a perfect binary subdivision?
  • Why can't I use more than two registers in inline asm?
  • A question of strstr() and fgets() in a demo from the book《Head First C》
  • the problem is from a algorithm problem I do recently,but I can't gain the right answer
  • Problem to access members in pointer struct located in another pointer struct
  • Check that all symbols defined in static library
  • Function will only properly work if I've printed the values of the attributes
  • Why my code is showing time limit exceeded
  • #define statement for address of memory
  • How to call a function from another .c file
  • Memory layout of C struct
  • Why should we use return statement when using a recursive call?
  • error: expected identifier or '(' before '=' token
  • Why is it not possible to exchange the position of array name and index in swift like C (a[i] == i[a])?
  • How can I allocate enough memory to store an entire text file in C?
  • Segmentation fault when I use afl fuzzer
  • What happens in the assembly output when we add "cc" to clobber list
  • What is the equivalent of Keil _at_ in gcc
  • Simple question about declaring an empty string in C
  • Heap-Overflow or Buffer-Overflow?
  • C: Why is &= better that =?
  • Create exactly 5 process with fork()
  • gcc compile function in ifdef
  • where is the memory leak in the code below?
  • Most efficient formula for unpacking 16-bit BCD? (e.g. 0x1234 to 0x01020304)
  • how to find which integer no is maximim out of given numbers
  • Difference between a VOID function with a string argument VS a function with a string argument that returns a char array
  • why the output of the following program different (random value) every time?
  • Why does this macro expression in C behave unexpectedly?
  • When is memory allocated and de-allocated static and dynamic memory in C?
  • In C, what happens if we left shift the bits out of range and again right shift the values in the same operation
  • why the following c program is giving segmentation error?
  • adc frequency vs accuracy
  • why the output of following c program is 16 16 16?
  • Is it possible to declare a function in header file with unknown type that is specified only in file '.c'?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk