Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
C Program For Char to Int Conversion
Next article icon

C Program For Long to String Conversion

Last Updated : 03 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

To convert the long to string in C language we will use the following 2 approaches:

  1. Using Macros with sprintf
  2. Using sprintf

Input: 

long = 1234 

Output: 

string 1234

1. Using Macros and sprintf

C




// C Program for Long to 
// String Conversion
#include <stdio.h>
#include <string.h>
  
#define Max_Digits 10
int main()
{
    long N = 1243;
    char str[Max_Digits + sizeof(char)];
    sprintf(str, "%ld", N);
    printf("string is: %s \n", str);
}
 
 
Output
string is: 1243 

2. Using Sprintf 

C




// C Program for Long to String Conversion
#include <stdio.h>
  
int main()
{
  
    long x = 1234;
    char str[256];
    sprintf(str, "%ld", x);
    printf("The string is : %s", str);
    return 0;
}
 
 
Output
The string is : 1234


Next Article
C Program For Char to Int Conversion

L

laxmigangarajula03
Improve
Article Tags :
  • C Language
  • C Programs
  • C Conversion Programs

Similar Reads

  • C Program For Double to String Conversion
    To convert double to string in C language, we will use the sprintf function as follows: Input: n = 456321.7651234 Output: string: 456321.7651234 Method: Using sprintf By specifying the precision in sprintf, we can convert double to string or character array with custom precision. We can use sprintf
    1 min read
  • C Program For Char to Int Conversion
    Write a C program to convert the given numeric character to integer. Example: Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3. Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9. Different Methods to Convert the char to int in CThere are 3
    3 min read
  • C Program For Int to Char Conversion
    To convert the int to char in C language, we will use the following 2 approaches: Using typecastingUsing sprintf() Example: Input: N = 65 Output: A1. Using TypecastingMethod 1:Declaration and initialization: To begin, we will declare and initialize our integer with the value to be converted.Typecast
    2 min read
  • Converting String to Long in C
    Here, we will see how to build a C Program For String to Long Conversion using strtol() function. Syntax: long int strtol(char *string, char **ptr, int base)The first argument is given as a stringThe second argument is a reference to an object of type char*The third argument denotes the base in whic
    4 min read
  • Convert String to int in C
    In C, we cannot directly perform numeric operations on a string representing a numeric value. We first need to convert the string to the integer type. In this article, we will discuss different ways to convert the numeric string to integer in C language. Example: Input: "1234"Output: 1234Explanation
    6 min read
  • C Program to Find the Length of a String
    The length of a string is the number of characters in it without including the null character (‘\0’). In this article, we will learn how to find the length of a string in C. The easiest way to find the string length is by using strlen() function from the C strings library. Let's take a look at an ex
    2 min read
  • C program to find the frequency of characters in a string
    Given a string S containing lowercase English characters, the task is to find the frequency of all the characters in the string. ExamplesInput: S="geeksforgeeks" Output: e - 4 f - 1 g - 2 k - 2 o - 1 r - 1 s - 2 Input: S="gfg" Output: f - 1 g - 2Approach Follow the steps to solve the problem: Initia
    2 min read
  • How to Convert an Integer to a String in C?
    Write a C program to convert the given integer value to string. Examples Input: 1234Output: "1234"Explanation: The integer 1234 is converted to the string "1234". Input: -567Output: "-567"Explanation: The integer -567 is converted to the string "-567". Different Methods to Convert an Integer to a St
    4 min read
  • Lex program to find the Length of a String
    Problem: Write a Lex program to find the Length of a String Explanation: FLEX (Fast Lexical Analyzer Generator) is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt. Lex reads an input stream specifying the lexical analyzer and outputs source code impl
    1 min read
  • C Program to Concatenate Two Strings Using a Pointer
    Concatenating two strings means appending one string at the end of another string. While the standard library provides strcat() for concatenation, this article will demonstrate how to concatenate two strings using pointers. To concatenate two strings using pointers, traverse the first string to its
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences