Week 3 notes

Week 3 notes - n = number of args read n =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Week 3 notes You can use an array of characters to store the word when you are reading the characters.  #define MAXWORD 100 char word [MAXWORD]; i=0; while (c = getchar()) != EOF) { word [i] = c; i++; } else { if (i>0) { hello[i] = '\0'; i=0; printf("%s\n", word); RPN calculator: implement a stack function: push (x) x = pop() #define MAXSTACK 500 double stack [MAXSTACK]; int top=0; void push (double x) { if (top == MAXSTACK) { printf("stack full\n"); exit(1); } stack [top] = x; top++; } double pop() { if (top == 0) { printf("stack empty\n"); exit(1); } top--; double val = stack[top]; return val; } main (int argc, char **argv) { for (i=1; i<argc; i++) { double val = atof(argv[i]); push (val); int i; int n; double x; n = sscanf(str, "%d", &i);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n = number of args read n = sscanf(str, "%lf", &x); else if (strcmp(argv[i], "+") == 0) { double a = pop(); double b = pop(); push (a+b);} printf("%lf", result);} In a computer memory is stored as a sequence of bytes. A byte is a group of 8 bits. Each bit can be 0 or 1. Registers in CPU are 32 bits long in a 32 bit computer.Registers are 64 bit long in a 64 bit computer. In a 32-bit computer: 32 bits=4bytes=4*(8bits) smallest address=0 largest address=2^32-1 2^10=1024=1KB 2^20=2014*1024=1MB 2^30=1024*1024*1024=1GB A 32 bits CPU can have a memory of: (2^2)*(2^30)=4GB 4GB is the theoretical limit of memory that you can have in a program running in a 32-bit CPU....
View Full Document

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue.

Page1 / 2

Week 3 notes - n = number of args read n =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online