Visit Our UNIX and Linux User Community


help wid C-script in tcsh


 
Thread Tools Search this Thread
Top Forums Programming help wid C-script in tcsh
# 1  
Old 11-13-2007
Power help wid C-script in tcsh

Hello Freinds

I have just started off with Unix (TCSH) although I have a pretty sound background with C-programming. Kindly convey any error in foll script.

#include<stdio.h>
#include<math.h>
#define PI 3.142857
main ()
{
float r, A;
printf("Enter the value of radius: ");
scanf(" %f ",&r);
A = ((PI/4)*r*r);
printf("Area of circle is %f", A);
}

I can compile it with gcc but when I run it in terminal, it returns nothing, guess it goes into a loop.

Pls help
# 2  
Old 11-13-2007
Hm, sense of deja vu with this one.

Make r and A doubles.

The printf format "%f" actually works with doubles, not floats.

Things may have changed since my days at school, but I thought that area was

PI*r*r

Does it just hang?

Circle - Wikipedia, the free encyclopedia
# 3  
Old 11-13-2007
thanx porter

but still not working, even wid doubles.

it just hangs. I have to Ctrl-Z i.e. suspend it.
# 4  
Old 11-13-2007
just a thought

include<stdio.h>
include<math.h>
define PI 3.142857
main ()
{
float r, A;
printf("Enter the value of radius: ");
scanf(" %f ",&r);
A = (PI/4)*(r*r);
printf("Area of circle is %f", A);
}
# 5  
Old 11-13-2007
but its in C, so # is necessary at d beginning.

Just not able to get it runnin. Grrrr.....
# 6  
Old 11-13-2007
try C++

#include<stdio.h>
#include<math.h>
main ()
{
const float PI=3.142857;
double r, A;
A = (PI/4)*(r*r);

cout<<"Enter the value of radius: ";
cin>>r;

cout<<"Area of circle is "<< A;
}
# 7  
Old 11-13-2007
This works on Solaris using gcc.

Code:
#include<stdio.h>
#include<math.h>
#define PI 3.142857
int main(int argc,char **argv)
{
        float r, A;
        printf("Enter the value of radius: ");
        scanf("%f",&r);
        A = ((PI/4)*r*r);
        printf("Area of circle is %f", A);
        return 0;
}

even if I don't agree with the actual algorithm.

Note I changed the scanf to be purely "%f".

Code:
all: area

area: area.c
        $(CC) $(CFLAGS) -Wall -Werror area.c -o $@


Previous Thread | Next Thread
Test Your Knowledge in Computers #167
Difficulty: Easy
The Transmission Control Protocol (TCP) is one of the least used protocols of the Internet protocol suite.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions in tcsh script

Hi, I have a shell script in tcsh to which I pass an argument, the length of which can vary. The possible values of the argument are the letters -c,s,i,q,a. and also a combination of these letters. (e.g: cs,si,ca,iq,qa,csq,acs,csia ..etc). The order of the letters does not matter. My problem... (2 Replies)
Discussion started by: Vaisakh P
2 Replies

2. Shell Programming and Scripting

Tcsh complete (autocomplete) script

I cant figure out how the complete function works in tcsh. 1. I whould like it to complete after writing my_program.py with either start or stop. I have tried to do something like this in .cshrc.user: complete my_program.py \ 'c/start/' \ 'c/stop/' However i cant get it to... (1 Reply)
Discussion started by: mr_cad
1 Replies

3. Shell Programming and Scripting

Help in tcsh script

Hi All, I wrote a tcsh script, but being a beginner it took me lots of efforts and on top of that I am still struggling with little modifications here and there. kindly have a loop. Line1 : I want it to run maximum of "Max" Which I am providing outside loop. So how the "for" should be... (10 Replies)
Discussion started by: nrjrasaxena
10 Replies

4. Linux

Execution problem wid mpstat command

mpstat -P ALL 1 10 it results.. 08:05:54 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s 08:05:55 PM all 0.00 0.00 0.49 0.00 0.49 0.00 0.00 99.02 1024.75 08:05:55 PM 0 0.00 0.00 0.00 0.00 0.99 0.00 0.00 ... (1 Reply)
Discussion started by: pritesh_patil
1 Replies

5. Shell Programming and Scripting

tcsh env setting using shell script

Hi All, I have made a file file usercreate.sh & it has to run in tcsh env & needs some path to be set. my script is as below. ########################## #!/bin/csh setenv PATH "/usr/lib/java/class" setenv LD_LIBRARAY_PATH ########################### but when i am ruuning my script... (1 Reply)
Discussion started by: ajaincv
1 Replies

6. Shell Programming and Scripting

Help with gawk array, loop in tcsh script

Hi, I'm trying to break a large csv file into smaller files and use unique values for the file names. The shell script i'm using is tcsh and i'm after a gawk one-liner to get the desired outcome. To keep things simple I have the following example with the desired output. fruitlist.csv apples... (6 Replies)
Discussion started by: theflamingmoe
6 Replies

7. Shell Programming and Scripting

tcsh I can't get script to work :(

I have an export utility that exports documents from the native file to text. This is the way I would run it from the command line: expage "file" > "file.txt I am trying to loop through all the documents in the directory and expage them, here is the code: #!/usr/bin/env tcsh foreach file... (8 Replies)
Discussion started by: Fred Goldman
8 Replies

8. Shell Programming and Scripting

Help me with this tcsh script.!!!!

I need to write a tcsh script which would compare files in the two folders and then send me a mail saying which of the files are missing.For eg 1) I have this folder1 containing all the files which must land on folder2 on a daily basis. 2) If a file is present in folder1 but not in... (6 Replies)
Discussion started by: kumarsaravana_s
6 Replies

9. Shell Programming and Scripting

how to call a perl script from tcsh?

Hi I am not sure how to call a perl script from a tcsh shell. do i need to set any environment variables? your help is appreciated Thanks (1 Reply)
Discussion started by: megastar
1 Replies

10. UNIX for Dummies Questions & Answers

how to fork voice wid text???

hello... i am working in LINUX on a client/server voice communication project!!! so far i am done wid compiling code for reading/playin sound card and also sending text from server to client. now i need ur help in using fork() though i do have basic concept about fork but i need detail help in... (0 Replies)
Discussion started by: TAM
0 Replies

Featured Tech Videos