K & R C Programs Exercise 2-1.

K and R C, Solution to Exercise 2-1:
C program to determine the ranges of char, short, int and long variables, both signed and unsigned, by printing appropriate values from standard headers and by direct computation.the ANSIstandard for C specifies that ranges be defined in <limits.h>. K and R C Program. Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>
#include <limits.h>

int
main ()
{
printf("Range of Char %dn", CHAR_BIT);
printf("Range of Char Max %dn", CHAR_MAX);
printf("Range of Char Min %dn", CHAR_MIN);
printf("Range of int min %dn", INT_MIN);
printf("Range of int max %dn", INT_MAX);
printf("Range of long min %ldn", LONG_MIN);
printf("Range of long max %ldn", LONG_MAX);
printf("Range of short min %dn", SHRT_MIN);
printf("Range of short max %dn", SHRT_MAX);
printf("Range of unsigned char %un", UCHAR_MAX);
printf("Range of unsigned long %lun", ULONG_MAX);
printf("Range of unsigned int %un", UINT_MAX);
printf("Range of unsigned short %un", USHRT_MAX);

return 0;
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 1-24.

K and R C, Solution to Exercise 1-24:
C program for rudimentary syntax errors like unbalanced parentheses, brackets,quotes,and braces. This program is hard if we do it in full generality. K and R C Program Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>

#define MAXLINE 1000 /* max input line size */
char line[MAXLINE]; /*current input line*/

int getline(void); /* taken from the KnR book. */

int main() {
int len = 0;
int t = 0;
int brace = 0, parenthesis = 0, brack = 0;
int s_quote = 1, d_quote = 1;

while ((len = getline()) > 0) {
t = 0;
while (t < len) {
if (line[t] == '{') {
brace++;
}
if (line[t] == '}') {
brace--;
}
if (line[t] == '[') {
brack++;
}
if (line[t] == ']') {
brack--;
}
if (line[t] == '(') {
parenthesis++;
}
if (line[t] == ')') {
parenthesis--;
}
if (line[t] == ''') {
s_quote *= -1;
}
if (line[t] == '"') {
d_quote *= -1;
}
t++;
}
}
if (d_quote != 1)
printf("Mismatching double quote markn");
if (s_quote != 1)
printf("Mismatching single quote markn");
if (parenthesis != 0)
printf("Mismatching parenthesisn");
if (brace != 0)
printf("Mismatching bracesn");
if (brack != 0)
printf("Mismatching bracket markn");
if (brack == 0 && brace == 0 && parenthesis == 0 && s_quote == 1 && d_quote
== 1)
printf("Syntax appears to be correct.n");
return 0;
}

/* getline function */
int getline(void) {
int c, i;
extern char line[];

for (i = 0; i < MAXLINE - 1 && (c = getchar()) != EOF && c != 'n'; ++i)
line[i] = c;
if (c == 'n') {
line[i] = c;
++i;
}
line[i] = '';
return i;

}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 1-23.

K and R C, Solution to Exercise 1-23: C program that removes the all comments from a C Program. K and R C Program. Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"
void rcomment(int c);
void in_comment(void);
void echo_quote(int c);
main();
{
int c ,d;
while((c= getchar()) !=EOF)
rcomment(c);
return 0;
}
void rcomment(int c) {
int d;
if(c == '/')
if((d= getchar))=='*')
in_comment();
else if(d== '/') {
putchar(c);
rcomment(d);
} else {
putchar(c);
putchar(d);
}
else if(c=='' || c=='"')
echo_quote(c);

}
void in_comment() {
int c, d;
c = getchar();
d = getchar();
while (c!= '*' || d!!='/') {
c = d;
d = getchar();
}
}
void echo_quote(int c) {
int d;
putchar(c);
while ((d = getchar()) != c) {
putchar(d);
if (d == '\')
putchar(getchar());

}
putchar(d);
}
Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above. To get regular updates on new C programs, you can Follow @c_program
You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link

(c) www.c-program-example.com

K & R C Programs Exercise 1-22.

K and R C, Solution to Exercise 1-22:
 C program that folds the very long lines of input into two or more shorter lines. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"

#define MAXSIZE 1000

char line[MAXSIZE];

int get_line(void);


int
main()
{
int i,strlen;
int location, spaceholder;
const int foldlength=70;

while (( strlen = get_line()) > 0 )
{
if( strlen < foldlength )
{
}
else
{

i = 0;
location = 0;
while(i<strlen)
{
if(line[i] == ' ')
spaceholder = i;

if(location==foldlength)
{
line[spaceholder] = 'n';
location = 0;
}
location++;
i++;
}
}
printf ( "%s", line);
}
return 0;
}


int get_line(void)
{
int c, i;
extern char line[];

for ( i=0;i<MAXSIZE-1 && ( c=getchar()) != EOF && c != 'n'; ++i)
line[i] = c;
if(c == 'n')
{
line[i] = c;
++i;
}
line[i] = '';
return i;

}
Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 1-21.

K and R C, Solution to Exercise 1-21:
C Program to replace string of blanks by the minimum number of tabs and blanks to achieve the same spacing. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"
#define TABSIZE 6 /*Tab increment size*/
main() {
int c, no_blanks, pos, no_tabs;
no_blanks = 0; /*number of blamks required*/
no_tabs = 0; /* number of tabs required*/

for (pos = 1; (c = getchar()) != EOF; ++pos) {
if (c == ' ') {
if (pos % TABSIZE != 0)
++no_blanks;
else {
no_blanks = 0;
++no_tabs;
}
} else {
for (; no_tabs > 0; --no_tabs)
putchar('t');
if (c == 't')
no_blanks = 0;
else
for (; no_blanks > 0; --no_blanks)
putchar(' ');
putchar(c);
if (c == 'n')
pos = 0;
else if (c == 't')
pos = pos + (TABSIZE - (pos - 1) % TABSIZE);

}
}
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 1-20.

K and R C, Solution to Exercise 1-20:
C Program to replace the tabs by proper number of blanks. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"
#define TABSIZE 6 /*Tab increment size*/
main()
{
int c, no_blanks,pos;
no_blanks = 0; /*number of blamks required*/
pos = 1; /* position of the character*/
while((c=getchar()) != EOF){
if(c == 't'){
no_blanks = TABSIZE-(pos-1)%TABSIZE;
while(no_blanks>0){

putchar(' ');
++pos;
--no_blanks;
}
else if(c == 'n'){
putchar(c);
pos = 1;
} else {
putchar(c);
++pos;
}
}
}
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Programs Exercise 1-19

K and R C, Solution to Exercise 1-19:
Write a function reverse(str) that reverses the character string str. Use it to write program that reverse thes its input a line at a time. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"

#define MAXINLINE 1000 /* maximum input line size */

int get_lines(char line[], int maxline);
void reverse(char str[]);

/* print longest input line */
main() {

char line[MAXINLINE]; /* current input line */

while ((get_lines(line, MAXINLINE)) > 0) {

reverse(line);
printf("%s", line);

}

}

/* getline: read a line into s, return length */
int get_lines(char str[], int line) {
int c, i, j;

for (i = 0, j = 0; (c = getchar()) != EOF && c != 'n'; ++i) {
if (i < line - 1) {
str[j++] = c;
}
}
if (c == 'n') {
if (i <= line - 1) {
str[j++] = c;
}
++i;
}
str[j] = '';
return i;
}

/*reverse the string str*/
void reverse(char str[]) {
int i, j;
char temp;
i = 0;
while (str[i] != '')
++i;
--i;
if (str[i] != 'n')

--i;
j = 0;
while (j < i) {
temp = str[j];
str[j] = str[i];
str[i] = temp;
--i;
++j;
}
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K & R C Exercise 1-18

K and R C, Solution to Exercise 1-18:
Remove trailing blanks and tabs from each line of input, and to delete entirely blank lines. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"

#define MAXLINE 1000

int get_lines(char line[], int maxline);
int char remove(char str[]);

main()
{

char line[MAXINLINE];/* current input line */

while((get_lines(line,MAXINLINE))>0)
if(remove(line)> 0)
printf("%s", line);
return 0;

}
/*
remove trailing blanks and tabs from character string str
*/
int remove(char str[])
{
int i=0;
while(str[i] !='n')
++i;

--i;

while(i>=0 && (str[i]==' ' || str[i]=='t'))
--i;
if(i>=0)
{
++i;
s[i]='n';
++i;
s[i]='';

}
return i;
}
/* getline: read a line into str, return length */
int get_lines(char str[], int line)
{
int c, i, j;

for(i = 0, j = 0; (c = getchar())!=EOF && c != 'n'; ++i)
{
if(i < line - 1)
{
str[j++] = c;
}
}
if(c == 'n')
{
if(i <= line - 1)
{
str[j++] = c;
}
++i;
}
str[j] = '';
return i;
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link

(c) www.c-program-example.com

K&R C Program Exercise 1-17

K and R solution Exercise 1-17,to print all input lines that are longer than 80 characters. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include "stdio.h"
#define MAXINLINE 1000 /* maximum line sizes defined*/
#define LONGLINESIZE 80 /* longer line defined as 80 */
int get_lines(char line[], int maxline);
/*print lines longer than LONGLINESIZE */
main()
{
int len; /*current line length */
char line[MAXINLINE];/* current input line */
while((len=get_lines(line,MAXINLINE))>0)
if(len> LONGLINE)
printf("%s", line);
return 0;

}

/* getline: read a line into s, return length */
int get_lines(char s[], int line)
{
int c, i, j;

for(i = 0, j = 0; (c = getchar())!=EOF && c != 'n'; ++i)
{
if(i < line - 1)
{
s[j++] = c;
}
}
if(c == 'n')
{
if(i <= line - 1)
{
s[j++] = c;
}
++i;
}
s[j] = '';
return i;
}
Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

K&R C Program Exercise 1-16

K and R solutions to Revise the the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include "stdio.h"

#define MAXINLINE 1000 /* maximum input line size */

int getline(char line[], int MAXINLINE);
void copy(char to[], char from[]);

/* print longest input line */
int main(void)
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXINLINE]; /* current input line */
char longest[MAXINLINE]; /* longest line saved here */

max = 0;

while((len = getline(line, MAXINLINE)) > 0)
{
printf("%d: %s", len, line);

if(len > max)
{
max = len;
copy(longest, line);
}
}
if(max > 0)
{
printf("Longest LINE IN THE PROGRAM is %d characters:n%s", max, longest);
}
printf("n");
return 0;
}

/* getline: read a line into s, return length */
int getline(char s[], int line)
{
int c, i, j;

for(i = 0, j = 0; (c = getchar())!=EOF && c != 'n'; ++i)
{
if(i < line - 1)
{
s[j++] = c;
}
}
if(c == 'n')
{
if(i <= line - 1)
{
s[j++] = c;
}
++i;
}
s[j] = '';
return i;
}

/* copy: copy 'from' into 'to'; assume 'to' is big enough */
void copy(char to[], char from[])
{
int k;

k = 0;
while((to[k] = from[k]) != '')
{
++k;
}
}


Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link

(c) www.c-program-example.com