Back to lab04
Here's a review of some of what we learned in lab03 about atoi()
"30"
which are strings in C (i.e. char *
values) into integer values like 30
that can be stored in an int
variable.int x;
x = atoi("30");
./barOfStars 10
"10"
as argv[1]
, and use atoi to convert this from char *
to int
int width;
if (argc >= 2)
width = atoi(argv[1]);
#include <stdlib.h>
in our program before calling atoi().atoi()
comes from "ASCII to integer"atoi
, e.g. atoi("foo")
, we get back the value 0.atoi("4evah")
returns 4, and atoi("4.9999")
returns 4.If you need some more refreshers on how atoi works, go back to lab03 and go through the Ch session again.
Copyright 2009, Phillip T. Conrad, CS Dept, UC Santa Barbara. Permission to copy for non-commercial, non-profit, educational purposes granted, provided appropriate credit is given; all other rights reserved.