C Program To Remove Leading Zeros Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Here, we will build a C Program to Remove leading zeros with the following 2 approaches: Using for loopUsing strspn To remove all leading zeros from a number we have to give the input number as a string. Input: a = "0001234" Output: 12341. Using for loop C // C Program to Remove leading zeros // using for loop #include <stdio.h> #include <string.h> int main() { // input char a[1000] = "0001234"; int i, c = -1; // finding the all leading zeroes from the given string // and removing it from the string for (i = 0; i < strlen(a); i++) { if (a[i] != '0') { c = i; break; } } // printing the string again after removing the all // zeros for (i = c; i < strlen(a); i++) { printf("%c", a[i]); } return 0; } Output12342. Using strspn strspn: Returns the length of the first segment of str1 that exclusively contains characters from str2. C // C Program to Remove leading zeros // using strspn #include <stdio.h> #include <string.h> int main() { // input string char* s = "0001234"; int n; // strspn->Returns the length of the first segment of // str1 that exclusively contains characters from str2. if ((n = strspn(s, "0")) != 0 && s[n] != '\0') { // printing the string after eliminating the zeros printf("%s", &s[n]); } return 0; } Output1234 Comment L laxmigangarajula03 Follow 0 Improve L laxmigangarajula03 Follow 0 Improve Article Tags : C Programs C Language C Strings Programs Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like