Search found 141 matches

by BJT
Thu May 18, 2017 10:39 pm
Forum: C programming language Ritchie Kernighan
Topic: Self-referential Structures page 140, 141, 142, 143
Replies: 0
Views: 464
Gender:
Venezuela

Self-referential Structures page 140, 141, 142, 143

#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define MAXWORD 100 struct tnode { char *word; int count; struct tnode *left; struct tnode *right; }; struct tnode *addtree(struct tnode *, char *); void treeprint(struct tnode *); int getword(char *, int); /* word freque...
by BJT
Sun May 14, 2017 8:51 pm
Forum: C programming language Ritchie Kernighan
Topic: struct pointer keywords
Replies: 0
Views: 160
Gender:
Venezuela

struct pointer keywords

#include <stdio.h> #include <ctype.h> #include <string.h> struct key { char* word; int count; } keytab[] = { {"#define", 0}, {"#elif", 0}, {"#elifdef", 0}, {"#elifndef", 0}, {"#else", 0}, {"#endif", 0}, {"#error", 0}, {"#if", 0}, {"#ifdef", 0}, {"#ifndef", 0}, {"#include", 0}, {"#line", 0}, {"#prag...
by BJT
Sun May 14, 2017 5:46 pm
Forum: C programming language Ritchie Kernighan
Topic: Exercise 6-1 struct write a better version page 136
Replies: 0
Views: 239
Gender:
Venezuela

Exercise 6-1 struct write a better version page 136

Exercise 6-1. Our version of getword does not properly handle underscores, string constants, comments, or preprocessor control lines. Write a better version. #include <stdio.h> #include <ctype.h> #include <string.h> struct key { char* word; int count; } keytab[] = { {"#define", 0}, {"#elif", 0}, {"...
by BJT
Sat May 13, 2017 10:37 pm
Forum: C programming language Ritchie Kernighan
Topic: struct canonicalize coordinates of rectangle page 131
Replies: 0
Views: 806
Gender:
Venezuela

struct canonicalize coordinates of rectangle page 131

#include <stdio.h> #include <stdlib.h> #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) struct point { int x; int y; }; struct rect { struct point pt1; struct point pt2; }; struct rect canonrect(struct rect r); int main() { struct rect rec1={{200,300},{50,100}},re...
by BJT
Sat May 13, 2017 10:29 pm
Forum: C programming language Ritchie Kernighan
Topic: struct point inside of rectangel page 131
Replies: 0
Views: 75
Gender:
Venezuela

struct point inside of rectangel page 131

#include <stdio.h> #include <stdlib.h> struct point { int x; int y; }; struct rect { struct point pt1; struct point pt2; }; int ptinrect(struct point p1, struct rect r); int main() { struct point p1={10,10}; struct rect rec1={{0,0},{100,100}}; printf("%d \n",ptinrect(p1,rec1)); return EXIT_SUCCESS;...
by BJT
Sat May 13, 2017 10:16 pm
Forum: C programming language Ritchie Kernighan
Topic: Struct Add points page 130
Replies: 0
Views: 70
Gender:
Venezuela

Struct Add points page 130

#include <stdio.h> #include <stdlib.h> struct point { int x; int y; }; struct point addpoint(struct point p1, struct point p2); int main() { struct point p1={5,6},p2={10,20}; p1=addpoint(p1,p2); printf("%d %d\n",p1.x,p1.y); return EXIT_SUCCESS; } struct point addpoint(struct point p1, struct point ...
by BJT
Sat May 13, 2017 10:06 pm
Forum: C programming language Ritchie Kernighan
Topic: struct middel point page 130
Replies: 0
Views: 72
Gender:
Venezuela

struct middel point page 130

#include <stdio.h> #include <stdlib.h> #define XMAX 45 #define YMAX 50 struct point { int x; int y; }; struct rect { struct point pt1; struct point pt2; }; struct point makepoint(int x, int y); int main() { struct rect screen; struct point middle; screen.pt1=makepoint(0,0); screen.pt2=makepoint(XMA...
by BJT
Sat May 13, 2017 9:57 pm
Forum: C programming language Ritchie Kernighan
Topic: Struct function makepoint page 130
Replies: 0
Views: 62
Gender:
Venezuela

Struct function makepoint page 130

#include <stdio.h> #include <stdlib.h> struct point { int x; int y; }; struct point makepoint(int x, int y); int main() { struct point p1=makepoint(15,45); printf("%d %d\n",p1.x,p1.y); return EXIT_SUCCESS; } struct point makepoint(int x, int y) { struct point temp; temp.x=x; temp.y=y; return temp; ...
by BJT
Sat May 13, 2017 8:20 pm
Forum: C programming language Ritchie Kernighan
Topic: Exercise 5-20 page 126
Replies: 0
Views: 57
Gender:
Venezuela

Exercise 5-20 page 126

Exercise 5-20. Expand dcl to handle declarations with function argument types, qualifiers like const, and so on. #include<stdio.h> #include<string.h> #include<ctype.h> enum { NAME, PARENS, BRACKETS}; enum { NO, YES}; void dcl(void); void dirdcl(void); void errmsg(char *); void dclspec(void); int ty...
by BJT
Sat May 13, 2017 8:17 pm
Forum: C programming language Ritchie Kernighan
Topic: Exercise 5-19 undcl not add redundant parentheses page 126
Replies: 0
Views: 67
Gender:
Venezuela

Exercise 5-19 undcl not add redundant parentheses page 126

Exercise 5-19. Modify undcl so that it does not add redundant parentheses to declarations. #include <stdio.h> #include <string.h> #include <ctype.h> #define MAXTOKEN 100 enum { NAME, PARENS, BRACKETS }; int gettoken(void); char token[MAXTOKEN]; /*last token string */ char out[1000]; int tokentype; ...