repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
NightfallDM/xbook2
src/arch/x86/mach-i386/gate.c
#include <arch/segment.h> #include <arch/gate.h> #include <arch/interrupt.h> #include <arch/pic.h> #include <arch/registers.h> #include <xbook/kernel.h> /* * Interrupt descriptor table */ struct gate_descriptor *idt; // 总共支持的中断数 #define MAX_IDT_NR (IDT_LIMIT/8) /* 用户消息int软中断号,用于从用户态切换到内核态执行操作 */ #define KER...
NightfallDM/xbook2
library/xlibc/include/arch/x86/atomic.h
<reponame>NightfallDM/xbook2<filename>library/xlibc/include/arch/x86/atomic.h #ifndef _LIB_x86_ATOMIC_H #define _LIB_x86_ATOMIC_H /* 定义出口 */ void __atomic_add(int *a, int b); void __atomic_sub(int *a, int b); void __atomic_inc(int *a); void __atomic_dec(int *a); void __atomic_or(int *a, int b); void __atomic_and(int *...
NightfallDM/xbook2
src/arch/x86/include/arch/cpu.h
<reponame>NightfallDM/xbook2<filename>src/arch/x86/include/arch/cpu.h #ifndef _ARCH_CPU_H #define _ARCH_CPU_H #define cpu_lazy __cpu_lazy #define cpu_idle __cpu_idle static inline void arch_cpu_pause(void) { __asm__ __volatile__ ("pause"); } static inline void get_cpuid(unsigned int Mop,unsigned int S...
NightfallDM/xbook2
library/xlibc/math/fmod.c
<filename>library/xlibc/math/fmod.c /* File: fmod.c Contains: For x % y in float Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT fmod(M_FLOAT x, M_FLOAT y) { return (x - (int)(x / y) * y); }
NightfallDM/xbook2
src/net/net.c
<filename>src/net/net.c #include <xbook/netcard.h> #include <xbook/net.h> #include <xbook/clock.h> #include <xbook/task.h> #include <xbook/schedule.h> #include <lwip/netif.h> #include <lwip/ip.h> #include <lwip/tcp.h> #include <lwip/init.h> #include <netif/etharp.h> #include <lwip/timers.h> #include <lwip/udp.h> #incl...
NightfallDM/xbook2
src/kernel/softirq.c
#include <arch/interrupt.h> #include <xbook/debug.h> #include <xbook/softirq.h> #include <string.h> #include <xbook/bitops.h> /* 普通任务协助队列 */ task_assist_head_t task_assist_head; /* 高级任务协助队列 */ task_assist_head_t high_task_assist_head; /* 软中断表 */ static softirq_action_t softirq_table[NR_SOFTIRQS]; /* ...
NightfallDM/xbook2
src/arch/x86/include/arch/io.h
<gh_stars>0 #ifndef _ARCH_IO_H #define _ARCH_IO_H unsigned char __in8(unsigned int port); unsigned short __in16(unsigned int port); unsigned int __in32(unsigned int port); void __out8(unsigned int port, unsigned int data); void __out16(unsigned int port, unsigned int data); void __out32(unsigned int port, unsigned int...
NightfallDM/xbook2
src/include/xbook/bitops.h
#ifndef _XBOOK_BITOPS_H #define _XBOOK_BITOPS_H #include <arch/interrupt.h> /* 求位数值 */ #define low8(a) (unsigned char)((a) & 0xff) #define high8(a) (unsigned char)(((a) >> 8) & 0xff) #define low16(a) (unsigned short)((a) & 0xffff) #define high16(a) (unsigned short)(((a) >> 16) & 0xffff) #define low3...
NightfallDM/xbook2
library/xlibc/include/sys/proc.h
<reponame>NightfallDM/xbook2<filename>library/xlibc/include/sys/proc.h<gh_stars>0 #ifndef _SYS_PROC_H #define _SYS_PROC_H #include "kfile.h" #include <types.h> #define PROC_NAME_LEN 32 /* 任务状态 */ typedef struct _tstate { pid_t ts_pid; /* 进程id */ pid_t ts_ppid; /* 父进程id */ pid_t ts_tgid;...
NightfallDM/xbook2
src/include/xbook/gui.h
<filename>src/include/xbook/gui.h #ifndef _XBOOK_GUI_H #define _XBOOK_GUI_H void init_gui(); #endif /* _XBOOK_GUI_H */
NightfallDM/xbook2
library/xlibc/math/cos.c
/* File: cos.c Contains: For cos(x) Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT cos(M_FLOAT x) { return sin(x + MATH_PI_2); }
NightfallDM/xbook2
library/xlibc/include/sys/sys.h
<reponame>NightfallDM/xbook2<filename>library/xlibc/include/sys/sys.h<gh_stars>0 #ifndef _SYS_SYS_H #define _SYS_SYS_H #define SYS_VER_LEN 48 #endif /* _SYS_SYS_H */
NightfallDM/xbook2
user/bosh/main.c
#include <stdio.h> #include <xcons.h> #include <string.h> #include <unistd.h> #include "cmd.h" #include "shell.h" int main(int argc, char *argv[]) { printf("book os shell -v 0.01\n"); if (init_cmd_man() < 0) { printf("init cmd failed!\n"); return -1; } cmd_loop(); exit_cmd_man();...
NightfallDM/xbook2
src/gui/lowlevel/mouse.c
#include <string.h> #include <stdio.h> #include <xbook/driver.h> #include <sys/ioctl.h> #include <xbook/kmalloc.h> #include <xbook/vmarea.h> /// 程序本地头文件 #include <gui/mouse.h> #include <gui/screen.h> #include <gui/event.h> #include <sys/input.h> #include <gui/console/console.h> #include <gui/text.h> #include <gui/rec...
NightfallDM/xbook2
src/arch/x86/mach-i386/arch.c
<filename>src/arch/x86/mach-i386/arch.c #include <arch/segment.h> #include <arch/gate.h> #include <arch/tss.h> #include <arch/pmem.h> #include <arch/debug.h> #include <arch/pic.h> int init_arch() { /* the first thing is to init debug! */ init_kernel_debug(); /* init segment */ init_segment_descriptor(); ...
NightfallDM/xbook2
src/include/fsal/fstype.h
#ifndef _FILESRV_CORE_FSTYPE_H #define _FILESRV_CORE_FSTYPE_H #include <fsal/fsal.h> int fstype_register(fsal_t *fsal); int fstype_unregister(fsal_t *fsal); fsal_t *fstype_find(char *name); int init_fstype(); #endif /* _FILESRV_CORE_FSTYPE_H */
NightfallDM/xbook2
library/xlibc/math/sin.c
<filename>library/xlibc/math/sin.c<gh_stars>0 /* File: sin.c Contains: For sin(x) Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT sin(M_FLOAT x) { if (fabs(x) < EPSILON) return (0.0); x = -1.0 * (fmod(x...
NightfallDM/xbook2
src/include/xbook/diskman.h
<reponame>NightfallDM/xbook2 #ifndef _XBOOK_DISKMAN_H #define _XBOOK_DISKMAN_H #include <arch/atomic.h> #include <sys/res.h> #include "driver.h" /* 磁盘驱动器 */ typedef struct { list_t list; /* 信息链表 */ int solt; /* 插槽位置 */ int handle; /* 资源句柄 */ devent_t devent; /* 设备项 */ a...
NightfallDM/xbook2
src/arch/x86/include/arch/cmos.h
<reponame>NightfallDM/xbook2 #ifndef _X86_CMOS_H #define _X86_CMOS_H /** CMOS操作端口 **/ #define CMOS_INDEX 0x70 #define CMOS_DATA 0x71 /**CMOS中相关信息偏移*/ #define CMOS_CUR_SEC 0x0 //CMOS中当前秒?(BCD) #define CMOS_ALA_SEC 0x1 //CMOS中?警秒?(BCD) #define CMOS_CUR_MIN 0x2 //CMOS中当前分?(BCD) #define CMOS_ALA_MIN 0x3 ...
NightfallDM/xbook2
src/include/sys/ioctl.h
<filename>src/include/sys/ioctl.h #ifndef _SYS_IOCTL_H #define _SYS_IOCTL_H /* 设备控制码: 0~15位:命令(0-0x7FFF系统保留,0x8000-0xffff用户自定义) 16~31位:设备类型 */ #ifndef DEVCTL_CODE #define DEVCTL_CODE(type, cmd) \ ((unsigned int) ((((type) & 0xffff) << 16) | ((cmd) & 0xffff))) #endif /* 设备标志 */ #define DEV_NOWAIT...
NightfallDM/xbook2
library/xlibc/include/srv/netsrv.h
<filename>library/xlibc/include/srv/netsrv.h #ifndef _SRV_FILE_SRV_H #define _SRV_FILE_SRV_H /* file server call */ enum filesrv_call_num { NETSRV_SOCKET = 0, NETSRV_BIND, NETSRV_CONNECT, NETSRV_LISTEN, NETSRV_ACCEPT, NETSRV_SEND, NETSRV_RECV, NETSRV_CLOSE, NETSRV_SENDTO, NETSRV...
NightfallDM/xbook2
library/xlibc/math/tanh.c
/* File: tanh.c Contains: For tanh(x) Written by: GUI Copyright: (C) 2017-2020 by GuEe Studio for Book OS. All rights reserved. */ #include <math.h> M_FLOAT tanh(M_FLOAT x) { double pExponent, nExponent; pExponent = exp(x); nExponent = 1.0 / pExponent; return ((pExponent - ...
NightfallDM/xbook2
library/xlibc/include/sys/syscall.h
#ifndef _SYS_SYSCALL_H #define _SYS_SYSCALL_H enum syscall_num { SYS_EXIT, SYS_FORK, SYS_EXECR, SYS_EXECF, SYS_WAITPID, SYS_COEXIST, SYS_GETPID, SYS_GETPPID, SYS_TRIGGER, SYS_TRIGGERON, SYS_TRIGGERACT, SYS_TRIGRET, SYS_SLEEP, SYS_THREAD_CREATE, SYS_THREAD_EXI...
NightfallDM/xbook2
src/arch/x86/mach-i386/pmem.c
<reponame>NightfallDM/xbook2<filename>src/arch/x86/mach-i386/pmem.c #include <arch/pmem.h> #include <arch/page.h> #include <arch/bootmem.h> #include <xbook/debug.h> #include <math.h> #include <string.h> extern unsigned int get_memory_size_from_hardware(); /* 申请一个内存节点数组,通过引用来表明是否被使用 指向内存节点数组的指针 */ mem_node_t *mem_node...
NightfallDM/xbook2
src/arch/x86/mach-i386/debug.c
<reponame>NightfallDM/xbook2<gh_stars>0 #include <arch/debug.h> #include <arch/config.h> /** * init_kernel_debug * */ //define "debug_putchar" void (*debug_putchar)(char ch); void init_kernel_debug() { #if CONFIG_DEBUG_METHOD == 1 // 初始化控制台 init_console_debug(); debug_putchar = &console_putchar; #elif ...
NightfallDM/xbook2
src/include/xbook/pipe.h
<reponame>NightfallDM/xbook2<filename>src/include/xbook/pipe.h #ifndef _XBOOK_PIPE_H #define _XBOOK_PIPE_H #include "mutexlock.h" #include "fifobuf.h" #include "waitqueue.h" #include <list.h> #include <stdint.h> #include <types.h> #define PIPE_SIZE 4096 /* pipe flags */ enum { PIPE_NOWAIT = 0x01, }; /* 管道结构 ...
NightfallDM/xbook2
src/include/xbook/softirq.h
<reponame>NightfallDM/xbook2 #ifndef _XBOOK_SOFTIRQ_H #define _XBOOK_SOFTIRQ_H #include <arch/atomic.h> #include <types.h> #include <stddef.h> /* 软中断 */ /* 最大的软中断数量 */ #define MAX_NR_SOFTIRQS 32 #define MAX_REDO_IRQ 10 /* 定义软中断类型 */ enum { HIGHTASK_ASSIST_SOFTIRQ = 0, TIMER_SOFTIR...
NightfallDM/xbook2
library/xlibc/include/arch/x86/xchg.h
#ifndef _LIB_x86_XCHG_H #define _LIB_x86_XCHG_H char __xchg8(char *ptr, char value); short __xchg16(short *ptr, short value); int __xchg32(int *ptr, int value); /** * __Xchg: 交换一个内存地址和一个数值的值 * @x: 数值 * @ptr: 内存指针 * @size: 地址值的字节大小 * * 返回交换前地址中的值 */ static inline unsigned int __xchg(unsigned int x, v...
NightfallDM/xbook2
src/arch/x86/include/arch/time.h
#ifndef _ARCH_TIME_H #define _ARCH_TIME_H unsigned int cmos_get_hour_hex(); unsigned int cmos_get_min_hex(); unsigned char cmos_get_min_hex8(); unsigned int cmos_get_sec_hex(); unsigned int cmos_get_day_of_month(); unsigned int cmos_get_day_of_week(); unsigned int cmos_get_mon_hex(); unsigned int cmos_get_year(); voi...
feixian/ffmpegPackage
Example/ffmpegLib/ZYFViewController.h
// // ZYFViewController.h // ffmpegLib // // Created by hualaiTech on 10/10/2019. // Copyright (c) 2019 hualaiTech. All rights reserved. // @import UIKit; @interface ZYFViewController : UIViewController @end
NULLCT/YBTS
src/ofxNotification.h
#pragma once #include "ofMain.h" class ofxNotification { public: void set(ofTrueTypeFont &_font); void notice(ofColor _back, ofColor _word, string _text); void draw(); ofColor back, word; private: const int animelim = 60 * 2; bool drawtrigger = false; int countframe; int ypos; ...
NULLCT/YBTS
src/ofApp.h
<filename>src/ofApp.h #pragma once #include "ofMain.h" #include <limits> #include "ofxButton.h" #include "ofxNotification.h" #include "ofxNumSetter.h" #include "ofxPiyo.h" /* TODO: */ class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key); ...
NULLCT/YBTS
src/ofxPiyo.h
#pragma once #include <time.h> #include <random> #include "ofMain.h" class Piyo { public: Piyo(); void run(); double noisex = 0, noisey = 0; private: ofImage piyoimage; int lim = 200; int x, y, w, h; int replaceframe = 60 * 10; };
sharathbp/WarAndPeace
src/game.h
<reponame>sharathbp/WarAndPeace /* * game.h * * Created on: 01-May-2019 * Author: sharath */ #include <iostream> #include <stdlib.h> #include <list> #include <iterator> #include <string> #include <math.h> #include <GL/glut.h> #include "stb/stb_image.h" #pragma warning(disable:4996) usi...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_9/projects/01/01.c
<gh_stars>0 #include <stdio.h> void selection_sort(int arr[], int n); int main(void) { int i, arr[10]; printf("Please enter 10 integers: "); for (i = 0; i < 10; i++) scanf("%d", &arr[i]); selection_sort(arr, 10); printf("Sorted list: "); for (i = 0; i < 10; i++) printf("%d ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_7/projects/13/13.c
#include <stdio.h> int main(void) { char in_word, c; float word_count, total_word_length; printf("Enter a sentence: "); in_word = 0; total_word_length = 0; word_count = 0; while ((c = getchar()) != '\n') { if (c == ' ') { if (in_word) in_wo...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/10/10.c
#include <stdio.h> int main(void) { int input_hours, input_minutes, input_minutes_since_midnight; int departures[8] = {480, 583, 679, 767, 840, 945, 1140, 1305}; printf("Enter a 24-hour time: "); scanf("%2d:%2d", &input_hours, &input_minutes); input_minutes_since_midnight = input_hours * 60 + input_minute...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/09/9.c
#include <stdio.h> #include <ctype.h> int compute_vowel_count(const char *sentence); int main(void) { char sentence[81]; char c, *p = sentence; printf("Enter a sentence: "); while ((c = getchar()) != '\n' && p < sentence + 80) *p++ = c; p = '\0'; printf("Your sentence contains %...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_5/projects/11/11.c
<filename>chapter_5/projects/11/11.c<gh_stars>0 #include <stdio.h> int main(void) { int tens_digit, ones_digit; printf("Enter a two-digit number: "); scanf("%1d%1d", &tens_digit, &ones_digit); if (tens_digit == 1) switch (ones_digit) { case 0: printf("Ten"); ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/15/15.c
#include <stdio.h> int main(void) { char c, shifted_char; int shift_amount = 0; char message[80] = {0}; printf("Enter a message to be encrypted: "); for (int i = 0; (c = getchar()) != '\n'; i++) message[i] = c; printf("Enter shift amount (1-25): "); scanf("%d", &shift_amount); printf("Encrypted...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_7/projects/10/10.c
#include <stdio.h> #include <ctype.h> int main(void) { char c; int vowel_count = 0; printf("Enter a sentence: "); while ((c = getchar()) != '\n') { switch (tolower(c)) { case 'a': case 'e': case 'i': case 'o': case 'u': vowel_co...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_12/projects/04/4.c
<filename>chapter_12/projects/04/4.c #include <stdio.h> #include <ctype.h> #define MAX_LENGTH 100 int main(void) { char *p, *q, *r, message[MAX_LENGTH] = {0}; p = message; printf("Enter a message: "); for (char c; (c = getchar()) != '\n' && p < message + MAX_LENGTH;) if (isalpha(c)) ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/03/03.c
<gh_stars>0 /* Checks numbers for repeated digits */ #include <stdio.h> int main(void) { int digit, i, occurrences[10] = {0}; long n; printf("Enter a number: "); scanf("%ld", &n); if (n <= 0) { printf("Digit:\t\t 0 1 2 3 4 5 6 7 8 9\n"); printf("Occurrences:\t 0 0 ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/12/12.c
#include <stdio.h> #define MAX_WORDS 30 #define MAX_LEN 20 int main(void) { int i = 0, j = 0; char c; char terminating_char = 0; char sentence[MAX_WORDS][MAX_LEN + 1]; printf("Enter a sentence: "); while ((c = getchar()) != '\n' && i < MAX_WORDS) { if (c == ' ' || c == '\t') { ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_3/projects/01/01.c
<filename>chapter_3/projects/01/01.c #include <stdio.h> int main(void) { int day, month, year; printf("Enter a date (mm/dd/yyy): "); scanf("%d /%d /%d", &month, &day, &year); printf("You entered the date %.4d%.2d%.2d", year, month, day); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_5/projects/07/07.c
<filename>chapter_5/projects/07/07.c #include <stdio.h> int main(void) { int num_1, num_2, num_3, num_4, max, min; printf("Please enter 4 integers: "); scanf("%d %d %d %d", &num_1, &num_2, &num_3, &num_4); if (num_1 <= num_2 && num_1 <= num_3 && num_1 <= num_4) min = num_1; else if (num_2 <= num_1 && n...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/09/09.c
<filename>chapter_6/projects/09/09.c #include <stdio.h> int main(void) { float loan_amount, interest_rate, monthly_payment, monthly_interest_rate; int i, payments; printf("Enter amount of loan: "); scanf("%f", &loan_amount); printf("Enter interest rate: "); scanf("%f", &interest_rate); printf("Enter m...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_12/projects/03/3.c
#include <stdio.h> #define MAX_LENGTH 100 int main(void) { char *p, message[MAX_LENGTH] = {0}; p = message; printf("Enter a message: "); for (char c; (c = getchar()) != '\n' && message < &message[MAX_LENGTH - 1]; p++) *p = c; printf("Reversal is: "); for (; p >= message; p--) ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_2/exercises/04/04.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions<gh_stars>0 #include <stdio.h> int main(void) { int foo, bar, baz; float a, b, c; printf("Integers - foo: %d, bar: %d, baz: %d\n", foo, bar, baz); printf("Floats - a: %f, b: %f, c: %f\n", a, b, c); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/08/08.c
#include <stdio.h> #define STUDENTS 5 #define QUIZ_GRADES 5 int main(void) { int matrix[STUDENTS][QUIZ_GRADES], i, j, highest, lowest, total; for (i = 0; i < STUDENTS; i++) { printf("Enter quiz grades for student %d: ", i + 1); for (j = 0; j < QUIZ_GRADES; j++) scanf("%d", &m...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_7/projects/08/08.c
<gh_stars>0 #include <stdio.h> #include <ctype.h> int main(void) { int input_hours, input_minutes, input_minutes_since_midnight; char time_indicator; int departure_1 = 480; int departure_2 = 583; int departure_3 = 679; int departure_4 = 767; int departure_5 = 840; int departure_6 = 94...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/14/14.c
<filename>chapter_8/projects/14/14.c #include <stdio.h> #define SENTENCE_LENGTH 50 int main(void) { int i, j, k; char c; char debug; char sentence[SENTENCE_LENGTH] = {0}; char terminal; printf("Enter a sentence: "); for (int i = 0; (c = getchar()) != '\n'; i++) { if (c == '.' || c == '?' || c ==...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_11/projects/02/02.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> #define DEPARTURE 0 #define ARRIVAL 1 void find_closest_flight(int desired_time, int *departure_time, int *arrival_time); int main(void) { int input_hours, input_minutes, departure_hour, arrival_hour, desired_time, departure_t...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/02/02.c
#include <stdio.h> int main(void) { int number_1, temp, number_2, gcd; printf("Enter two integers: "); scanf("%d %d", &number_1, &number_2); for (;;) { if (number_1 == 0) { gcd = number_2; break; } if (number_2 == 0) { gcd = number_1; break; } temp = nu...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/02/02.c
<filename>chapter_8/projects/02/02.c<gh_stars>0 /* Checks numbers for repeated digits */ #include <stdbool.h> /* C99 only */ #include <stdio.h> int main(void) { int digits[10] = {0}; int i, digit; long n; printf("Enter a number: "); scanf("%ld", &n); while (n > 0) { digit = n %...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/02/2.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> #include <string.h> #define MAX_REMIND 50 #define MSG_LEN 60 int read_line(char str[], int n); int main(void) { char reminders[MAX_REMIND][MSG_LEN + 3]; char day_str[22], msg_str[MSG_LEN + 1]; int month, day, hour, mi...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/06/06.c
#include <stdio.h> int main(void) { int max, squarable; printf("Please enter a number: "); scanf("%d", &max); for (squarable = 2; (squarable * squarable) <= max; squarable += 2) printf("%d\n", (squarable * squarable)); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/12/12.c
<gh_stars>0 #include <stdio.h> #include <ctype.h> int main(void) { char c; int values[26] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10}; int value = 0; int index = 0; printf("Enter a word: "); while ((c = getchar()) != '\n') { index = toupper(c) - 'A'; value...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/01/1.c
<filename>chapter_13/projects/01/1.c<gh_stars>0 #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdbool.h> #define MAX_WORD_LENGTH 20 int main(void) { char smallest_word[MAX_WORD_LENGTH], largest_word[MAX_WORD_LENGTH], word[MAX_WORD_LENGTH]; int comparison; printf("Enter a word: "); ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_4/projects/04/04.c
#include <stdio.h> int main(void) { int number, octal_digit_1, octal_digit_2, octal_digit_3, octal_digit_4, octal_digit_5; printf("Enter a number between 0 and 32767:"); scanf("%d", &number); octal_digit_5 = number % 8; number /= 8; octal_digit_4 = number % 8; number /= 8; octal_digit_3 = numbe...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_5/projects/06/06.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions /* Computes a Universal Product Code check digit */ #include <stdio.h> int main(void) { int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, first_sum, second_sum, total, check_digit; printf("Enter UPC digits: "); scanf("%1d%1d%1d%1d%1d%1d%1...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_9/projects/06/06.c
<gh_stars>0 #include <stdio.h> int power(int x, int n); int compute_polynomial(int x); int main(void) { int x; printf("Please provide a value for x: "); scanf("%d", &x); return compute_polynomial(x); } int power(int x, int n) { return n == 1 ? x : (x * power(x, n - 1)); } int compute_polynomial(int x) {...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/11/11.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> int main(void) { int n, i, j, factorial_i; float e; printf("Please enter a number: "); scanf("%d", &n); for (e = 1.00f, i = 1; i <= n; ++i) { for (factorial_i = 1, j = 1; j <= i; ++j) { ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/10/10.c
<gh_stars>0 #include <stdio.h> int main(void) { int day, month, year, min_day, min_month, min_year; printf("Enter a date (mm/dd/yyyy): "); scanf("%d/%d/%d", &min_month, &min_day, &min_year); for (;;) { printf("Enter a date (mm/dd/yyyy): "); scanf("%d/%d/%d", &month, &day, &year); ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_7/projects/11/11.c
#include <stdio.h> int main(void) { char initial, c; printf("Enter a first and last name: "); while ((c = getchar()) == ' ') ; initial = c; while ((c = getchar()) != ' ') ; while ((c = getchar()) == ' ') ; do putchar(c); while ((c = getchar()) != '...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_9/projects/07/07.c
#include <stdio.h> int power(int x, int n); int main(void) { int x, n; printf("Please enter x: "); scanf("%d", &x); printf("Please enter n: "); scanf("%d", &n); printf("Result: %d", power(x, n)); return 0; } int power(int x, int n) { if (n == 0) return 1; else if (n % 2 == 0) return pow...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_10/projects/06/06.c
#include <stdio.h> #include <stdbool.h> #include <stdlib.h> #define STACK_SIZE 100 int contents[STACK_SIZE]; int top = 0; void make_empty(void); bool is_empty(void); bool is_full(void); void push(int i); int pop(void); void stack_overflow(void); void stack_underflow(void); int main(void) { char c; printf("Enter...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_4/projects/01/01.c
#include <stdio.h> int main(void) { int number, digit_1, digit_2; printf("Enter a two-digit number:"); scanf("%d", &number); digit_1 = number / 10; digit_2 = number % 10; printf("The reversal is: %d%d", digit_2, digit_1); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/06/06.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> #include <ctype.h> #define MAX_MESSAGE_LENGTH 120 int main(void) { char c, original_message[MAX_MESSAGE_LENGTH] = {0}; int i = 0; printf("Enter message: "); while ((c = getchar()) != '\n' && i < MAX_MESSAGE_LENGTH) o...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_5/projects/10/10.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> int main(void) { int grade; printf("Enter numberical grade: "); scanf("%d", &grade); if (grade > 100 || grade < 0) printf("Invalid grade given."); else { printf("Letter grade: "); s...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_2/projects/05/05.c
#include <stdio.h> int main(void) { int x, result; printf("Enter a value for x: "); scanf("%d", &x); result = (3 * (x * x * x * x * x)) + (2 * (x * x * x * x)) - (5 * (x * x * x)) - (x * x) + (7 * x) - 6; printf("The result is %d", result); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_2/projects/07/07.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions<gh_stars>0 #include <stdio.h> int main(void) { int dollar_amount, bills_of_twenty, bills_of_ten, bills_of_five, bills_of_one; printf("Enter a dollar amount: "); scanf("%d", &dollar_amount); bills_of_twenty = dollar_amount / 20; dollar_amou...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/10/10.c
<filename>chapter_13/projects/10/10.c #include <stdio.h> void reverse_name(char *name); int main(void) { char name[81]; printf("Enter a first and last name: "); fgets(name, sizeof(name), stdin); reverse_name(name); return 0; } void reverse_name(char *name) { char *p = name, initial; ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/13/13.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> #define MAX_VALUE 80 void encrypt(char *message, int shift); int main(void) { char c, sentence[MAX_VALUE] = {0}; int i, n; printf("Enter message to be encrypted: "); for (i = 0; (c = getchar()) != '\n' && i < MA...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_3/projects/03/03.c
<filename>chapter_3/projects/03/03.c #include <stdio.h> int main(void) { int gs1_prefix, group_identifier, publisher_code, item_number, check_digit; printf("Enter ISBN: "); scanf("%d -%d -%d -%d -%d", &gs1_prefix, &group_identifier, &publisher_code, &item_number, &check_digit); printf("GS1 prefix: %d\n", gs1...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/11/11.c
#include <stdio.h> #include <ctype.h> double compute_average_word_length(const char *sentence); int main(void) { char sentence[101]; printf("Enter a sentence: "); fgets(sentence, sizeof(sentence), stdin); printf("Average word length: %.1f\n", compute_average_word_length(sentence)); ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_7/projects/06/06.c
#include <stdio.h> int main(void) { printf("Size of short: %lu\n", sizeof(short)); printf("Size of int: %lu\n", sizeof(int)); printf("Size of long: %lu\n", sizeof(long)); printf("Size of float: %lu\n", sizeof(float)); printf("Size of double: %lu\n", sizeof(double)); printf("Size of long double:...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_2/projects/08/08.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> int main(void) { float loan_amount, interest_rate, monthly_payment, monthly_interest_rate; printf("Enter amount of loan: "); scanf("%f", &loan_amount); printf("Enter interest rate: "); scanf("%f", &interest_rate); pri...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_10/projects/07/07.c
<filename>chapter_10/projects/07/07.c #include <ctype.h> #include <stdio.h> #include <stdlib.h> #define MAX_DIGITS 10 int digits[3][MAX_DIGITS * 4]; int segments[10][7] = { {1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 0, 0, 0, 0}, {1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 1}, {1, 0,...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_9/projects/03/03.c
#include <stdio.h> #include <stdlib.h> /* srand(), rand() */ #include <time.h> /* time() */ typedef int Bool; #define SIDE 10 #define DIRECTIONS 4 void generate_random_walk(char board[SIDE][SIDE]); void print_array(char board[SIDE][SIDE]); int main(void) { char board[SIDE][SIDE]; generate_random_walk(board);...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/01/01.c
<gh_stars>0 /* Checks numbers for repeated digits */ #include <stdbool.h> /* C99 only */ #include <stdio.h> int main(void) { bool digit_seen[10] = {false}; bool digit_repeated[10] = {false}; int i, digit; long n; printf("Enter a number: "); scanf("%ld", &n); while (n > 0) { ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_2/projects/03/03.c
#include <stdio.h> int main(void) { int radius; float volume; printf("Provide the radius of the sphere in meters: "); scanf("%d", &radius); volume = (4.0f / 3.0f) * 3.141592 * (radius * radius * radius); printf("The volume of a shpere with a %d-meter radius is: %f", radius, volume); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_4/projects/03/03.c
#include <stdio.h> int main(void) { int digit_1, digit_2; printf("Enter a two-digit number:"); scanf("%1d%1d", &digit_1, &digit_2); printf("The reversal is: %d%d", digit_2, digit_1); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
test.c
#include <stdio.h> #define SENTENCE_LENGTH 50 int main(void) { char *p, *q, c, terminal, sentence[SENTENCE_LENGTH] = {0}; printf("Enter a sentence: "); for (p = sentence; (c = getchar()) != '\n'; p++) { if (c == '.' || c == '?' || c == '!') { terminal = c; break; } else *p ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_5/projects/03/03.c
<filename>chapter_5/projects/03/03.c /* Calculates a broker's commission */ #include <stdio.h> int main(void) { float commission, rival_commission, total_trade_value, shares_amount, shares_value; printf("Enter the amount of shares traded: "); scanf("%f", &shares_amount); printf("Enter the value per share: "...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/08/8.c
<filename>chapter_13/projects/08/8.c #include <stdio.h> #include <ctype.h> int compute_scrabble_value(const char *word); int main(void) { int sum; char word[81]; printf("Enter a word: "); scanf("%s", word); printf("Scrabble value: %d\n", compute_scrabble_value(word)); return 0; } int compu...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/08/08.c
#include <stdio.h> int main(void) { int num_of_days, offset_days, starting_day, i; printf("Enter number of days in month: "); scanf("%d", &num_of_days); printf("Enter starting day of the week (1=Mon, 7=Sun): "); scanf("%d", &starting_day); offset_days = starting_day - 1; printf("\n\nMon...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/14/14.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> #include <ctype.h> /* toupper, isalpha */ #include <stdbool.h> /* C99+ only */ bool are_anagrams(const char *word1, const char *word2); int main(void) { char c, word1[80], word2[80], *p; p = word1; printf("Enter firs...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_9/projects/08/08.c
#include <stdio.h> #include <stdlib.h> /* srand(), rand() */ #include <time.h> /* time() */ #include <ctype.h> /* toupper() */ int play_game(void); int roll_dice(void); #define DICE_SIDES 6 #define PLAY_AGAIN 'Y' int main(void) { int outcome, wins = 0, losses = 0; char play_again = PLAY_AGAIN; srand((unsig...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/16/16.c
#include <stdio.h> #include <ctype.h> int main(void) { char c; int is_anagram = 1; int alphabet[26] = {0}; printf("Enter first word: "); for (int i = 0; (c = getchar()) != '\n'; i++) if (isalpha(c)) alphabet[tolower(c) - 'a']++; printf("Enter second word: "); for (int i = 0; (c = getchar())...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/17/17.c
<gh_stars>0 #include <stdio.h> int main(void) { int magic_square_side = 0; int max_side_index, row, col, next_row, next_col; int square[99][99] = {0}; printf("Enter size of magic square: "); scanf("%d", &magic_square_side); max_side_index = magic_square_side - 1; row = 0; col = max_side_index / 2; ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_8/projects/07/07.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> #define MAX_COL 5 #define MAX_ROW 5 int main(void) { int matrix[MAX_ROW][MAX_COL], i, j, total; for (i = 0; i < MAX_ROW; i++) { printf("Enter row %d: ", i + 1); for (j = 0; j < MAX_COL; j++) { ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_3/projects/04/04.c
#include <stdio.h> int main(void) { int phone_number_group_1, phone_number_group_2, phone_number_group_3; printf("Enter phone number: [(xxx) xxx-xxxx]: "); scanf("(%d )%d -%d", &phone_number_group_1, &phone_number_group_2, &phone_number_group_3); printf("You entered %d.%d.%d", phone_number_group_1, phone_num...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_11/projects/03/03.c
#include <stdio.h> void reduce(int numerator, int denominator, int *reduced_numerator, int *reduced_denominator); int main(void) { int numerator, denominator, ; printf("Enter a fraction: "); scanf("%d/%d", &numerator, &denominator); reduce(numerator, denominator, &numerator, &denominator); prin...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_3/projects/05/05.c
<gh_stars>0 #include <stdio.h> int main(void) { int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n13, n12, n14, n15, n16; printf("Enter numbers from 1 to 16 in any order:\n"); scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9, &n10, &n11, &n13, &n12, ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_6/projects/12/12.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> int main(void) { int n, i, factorial_i; float e, epsilon, current_term; printf("Please enter a number: "); scanf("%d", &n); for (e = 1.00f, factorial_i = 1, i = 1; current_term >= epsilon; ++i) { f...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_13/projects/18/18.c
#include <stdio.h> int main(void) { int m, d, y; char *months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; printf("Enter a date (mm/dd/yyyy): "); scanf("%d / %d / %d",...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_7/projects/07/07.c
/* Adds two fractions */ #include <stdio.h> int main(void) { int num1, denom1, num2, denom2, result_num, result_denom; char operator; printf("Enter two fractions separated by an operator (* / + or -): "); scanf("%d /%d %c %d /%d", &num1, &denom1, &operator, & num2, &denom2); switch (operator) ...
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_2/projects/02/02.c
#include <stdio.h> int main(void) { int radius; float volume; radius = 10; volume = (4.0f / 3.0f) * 3.141592 * (radius * radius * radius); printf("The volume of a shpere with a 10-meter radius is: %f", volume); return 0; }
reinvanimschoot/c-programming-a-modern-approach-solutions
chapter_5/projects/05/05.c
<reponame>reinvanimschoot/c-programming-a-modern-approach-solutions #include <stdio.h> int main(void) { float taxable_amount, income_tax; printf("Please enter the taxable amount: "); scanf("%f", &taxable_amount); if (taxable_amount < 750.0f) income_tax = taxable_amount * .01f; else if (taxable_amount <...