w3resource logo


C Programming Exercises

C Exercises: Convert a string to an unsigned long integer

C Variable Type : Exercise-2 with Solution

Write a C program to convert a string to an unsigned long integer.

Sample Solution:

C Code:

	int main ()
		char buffer[123];
		unsigned long ul;
		printf ("\nInput an unsigned number: ");
		fgets (buffer,123,stdin);

		ul = strtoul (buffer,NULL,0);
		printf ("Output: %lu\n\n",ul);
		return 0;

Sample Output:

Input an unsigned number: 25                                                                                  
Output: 25  

C Programming Code Editor:

Improve this sample solution and post your code through Disqus