Found 1401 Articles for C

C program to print a string without any quote in the program

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

628 Views

This is another tricky problem. In this program, we will see how to print a string using C where no quotation marks are used.Here we are using macro function. We are defining a macro function like#define getString(x) #xThe getString() is a macro function. It returns x by converting it into a string. The # before x is denoting that the function will convert x into a string.Input: Take one string without quote Output: Print that string into consoleAlgorithmStep 1:Take a string without quote Step 2: Use macro function to print it into a string Step 3: EndExample Code Live Demo#include #define ... Read More

C program to copy string without using strcpy() function

Nitya Raut
Updated on 30-Jul-2019 22:30:25

446 Views

In this section we will see how to copy a string to other string without using strcpy() function. To solve this problem we can write our own function that can act like strcpy(), but here we will follow some trick. We will use another library function to copy a string into another.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we ... Read More

C Program to convert a number to a string

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

13K+ Views

In this section we will see how to convert a number (integer or float or any other numeric type data) to a string.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.Input: User will put some numeric value say 42.26 Output: This program will return the string equivalent result of that number like "42.26"AlgorithmStep 1: Take ... Read More

Where do I find the current C or C++ standard documents?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

215 Views

In this post you can get some details where you can buy and view free drafts of some current and past C/C++ standards.C DocumentsC11:198 CHF (https://www.iso.org/standard/57853.html)Publicly at (http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf)Wikipedia Link (https://en.wikipedia.org/wiki/C11_(C_standard_revision))C99:Cannot Purchase (https://www.iso.org/standard/29237.html)Publicly at (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf)Wikipedia Link (https://en.wikipedia.org/wiki/C99)C90, C89, ANSI C, Standard CWikipedia Page: (https://en.wikipedia.org/wiki/ANSI_C)C++ DocumentsC++14:198 CHF (https://www.iso.org/standard/64029.html)Based On (https://www.iso.org/standard/29237.html)Wikipedia Link (https://en.wikipedia.org/wiki/ANSI_C)C++11:Cannot Purchase (https://www.iso.org/standard/50372.html)Publicly at (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf)Wikipedia Link (https://en.wikipedia.org/wiki/C%2B%2B11)C++03Wikipedia Page: (https://en.wikipedia.org/wiki/C%2B%2B03)C++89Wikipedia Page: (https://en.wikipedia.org/wiki/C%2B%2B)Read More

When can I use a forward declaration in C/C++?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

711 Views

In C++ the forward declaration lets the code following the declaration know that there is are classes with the name Person. This satisfies the compiler when it sees these names used. Later the linker will find the definition of the classes.Example CodeClass Person; void myFunc(Person p1) { // ... } Class Person { // Class definition here };So in this case when compiler encounters myFunc, it'll know that it is going to encounter this class somewhere down in the code. This can be used in cases where code using the class is placed/included before the code containing the class definition.

Why isn't sizeof for a struct equal to the sum of sizeof of each member in C/C++?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

721 Views

The size of a struct type element taken by sizeof() is not always equal to the size of each individual member. Sometimes the compilers add some padding to avoid alignment issues. So the size may change. The padding is added when a structure member is followed by a member with a larger size or at the end of the structure. Different compiler has different types of alignment constraints. In C standard, the total alignment structure depends on the implementation.Case 1In this case the double z is 8-byte long, which is larger than x (4-byte). So another 4-byte padding is added. ... Read More

C Program to display hostname and IP address

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see how to see the Host name and IP address of the local system in an easier way. We will write a C program to find the host name and IP.Some of the following functions are used. These functions have different task. Let us see the functions and their tasks.FunctionDescriptiongethostname()It finds the standard host name for the local computer.gethostbyname()It finds the host information corresponding to a host name from host databaseiten_ntoa()It converts an IPv4 Internet network address into an ASCII string into dotted decimal format.Example Code#include #include #include #include #include ... Read More

C Program to print hollow pyramid and diamond pattern

George John
Updated on 30-Jul-2019 22:30:25

3K+ Views

Here we will see how to generate hollow pyramid and diamond patterns using C. We can generate solid Pyramid patterns very easily. To make it hollow, we have to add some few tricks.Hollow PyramidFor the pyramid at the first line it will print one star, and at the last line it will print n number of stars. For other lines it will print exactly two stars at the start and end of the line, and there will be some blank spaces between these two starts.Example Code#include int main() {    int n, i, j;    printf("Enter number of lines: ... Read More

C program to print digital clock with current time

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see how to make a digital clock using C. To work with time we can use the time.h header file. This header file has some function signatures that are used to handle date and time related issues.The four important components of time.h is like belowsize_t This size_t is basically the unsigned integral type. This is the result of sizeof().clock_t This is used to store the processor timetime_t This is used to store calendar timestruct tm This is a structure. It helps to hold the entire date and time.Example Code#include #include int main() { ... Read More

C program to write an image in PGM format

Chandu yadav
Updated on 30-Jul-2019 22:30:25

1K+ Views

The PGM is the Portable Gray Map. If we want to store a 2d array in C as images in PNG, JPEG, or any other image format, we have to do lots of work to encode the data in some specified format before writing into a file.The Netpbm format gives an easy and portable solution. The Netpbm is an open source package of graphics program and it is used basically in linux or Unix platform. It also works under Microsoft Windows systems.Each file starts with a two-byte magic number. This magic number is used to identify the type of the ... Read More

Advertisements