Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
The problem statement, all variables and given/known data:
Do not know how to implement this into a script in Unix?
Relevant commands, code, scripts, algorithms:
Hello folks!
I need help on this one:
I have this C known program which I need to save it as "power2.c", and create it as a file in my UNIX environment:
/* power2.c -- Print out powers of 2: 1, 2, 4, 8, .. up to 2^N */
#include
#define N 16
int main(void) {
int n; /* The current exponent */
int val = 1; /* The current power of 2 */
printf("\t n \t 2^n\n");
printf("\t================\n");
for (n=0; n<=N; n++) {
printf("\t%3d \t %6d\n", n, val);
val = 2*val;
}
return 0;
}
/* It prints out :
n 2^n
===============
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8196
14 16384
15 32768
16 65536
*/
Any idea on how to perform this task?
[/INDENT]
3. The attempts at a solution (include all code and scripts):
Save it in text and save it power2.c but nothing works.
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
COL TECH / COL SPRINGS / US / BET TIMPTON / COURSE: IT358-103B.
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
How did you try to save it to a file? There are many editors for UNIX just as with Windows. Is saving it the problem or running it? You know to compile it next...?
you'd generally type:
cc -o power2 power2.c
and then run it, like so:
./power2
edit: OH, the problem is you need to rewrite this C program into a shell script??
Do you understand the C program already? What do you know about shell? Which shell are you learning (Bash? Korn? "sh"?)
If its a c program, it cant be a shell script...
But as a c source program only it can be saved which is nothing more than a ascii text file for unix and so can be read by any editor such as vi...
If its being copied from windows then you would have to check if it doesnt need to be converted using tools such a ux2dos or unix2dos ...
Then only can you try to compile it... as shown by the 2 posts above