C program into UNIX?

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions C program into UNIX?
# 1  
Old 12-19-2013
Wrench C program into UNIX?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Do not know how to implement this into a script in Unix?Smilie

2. 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:
Code:
/* 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?
3. The attempts at a solution (include all code and scripts):

Save it in text and save it power2.c but nothing works.

4. 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).

Last edited by vbe; 12-20-2013 at 06:18 AM.. Reason: code tags
# 2  
Old 12-19-2013
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:
Code:
cc -o power2 power2.c

and then run it, like so:
Code:
./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"?)
# 3  
Old 12-19-2013
It is not a script, it is a C program.

Try gcc program.c to turn it into a program named a.out
# 4  
Old 12-19-2013
I just pasted it in text and save as. Dont know what to do next.

I do not know how to compile it.

Sorry I dont use Unix a lot so I am lost

---------- Post updated at 05:40 PM ---------- Previous update was at 05:39 PM ----------

How do I make this C program into a shel in Unix?
# 5  
Old 12-20-2013
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
# 6  
Old 12-20-2013
Quote:
Originally Posted by kinelisch
I just pasted it in text and save as. Dont know what to do next.

I do not know how to compile it.
Try following the instructions I gave you.

Quote:
How do I make this C program into a shel in Unix?
You don't. It isn't.
# 7  
Old 12-22-2013
I tried the commands above and gave me error
Code:
$ gcc
-bash: gcc: command not found

I am using Cygwin in my windows machine
The c file I have saved into the desktop.

Last edited by Scott; 12-22-2013 at 07:26 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

C program into UNIX?

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... (1 Reply)
Discussion started by: kinelisch
1 Replies

2. Shell Programming and Scripting

Running C program in UNIX

I want to run a C program from my BASH script. Here's some very basic simplified code of my bash script: #!/bin/bash echo "Run C program" ./main.c echo "Ran C program" Here's my main.c: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { ... (3 Replies)
Discussion started by: millsy5
3 Replies

3. Homework & Coursework Questions

Need help with Basic Unix Program

I am a newbie to UNIX. I'm learning UNIX on my own, just trying to get the jerk of how things work in UNIX environment. I am familiar with Windows environment. Can anyone pls write simple 'envprint' programs to : 1) List all the environment Information (using the -l or --l options) 2) ... (1 Reply)
Discussion started by: agup17
1 Replies

4. UNIX for Advanced & Expert Users

C socket program on UNIX

Write a C socket program on UNIX where a TCP client sends/reads a time in decimal 24 hours format to the server and the server echoes the seconds, minutes, and hours in the time. Example: Client sends 18.78 hours and the server displays 18 hours, 46 minutes and 48 seconds. (1 Reply)
Discussion started by: adi_always4u143
1 Replies

5. Programming

compiling c program in unix

if somebody can help me pls. i need the source code for a shell which compiles C or java programs in unix i need a very short and simple one, just the compiling part Respect (2 Replies)
Discussion started by: zlatan005
2 Replies

6. UNIX for Dummies Questions & Answers

UNIX program?

Is there a program out there than runs like the UNIX operating system except in Window mode on Windows XP? Kind of like command prompt cmd.exe? (1 Reply)
Discussion started by: threewingedfury
1 Replies

7. Shell Programming and Scripting

Sorting Program In UNIX

Write a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program should generate an error message in case any input file does not... (1 Reply)
Discussion started by: kumar_saurabh
1 Replies

8. Programming

getting username from a c program in unix

How to get the user name of the Operating system from a c program. eg:- -rw-r----- 1 gkuser srth1 292 Jul 27 19:28 u1.txt i need to get gkuser as the result? (3 Replies)
Discussion started by: Rajeshsu
3 Replies

9. UNIX for Dummies Questions & Answers

Help with UNIX Program

I am trying to set up a file for someone and they have a program that was built for UNIX. I am guessing that it is running in some sort of emulator since they are on WinXP. It is a database and we are trying to get all of the addresses out of the database. I talked to the tech support for the... (7 Replies)
Discussion started by: brand1m
7 Replies

10. UNIX for Advanced & Expert Users

looking for a unix C program...help please

Hey Guys, Does anyone have a copy of a c-program which saves/writes files to a sub-directory within the home directory which uses the prototype::: save (char* filename, char* directory_name)::: if at all possible, could share that syntax with me please. Thanx much..... Peace... (3 Replies)
Discussion started by: richardspence2
3 Replies
Login or Register to Ask a Question