Tau Empire Codex 2013 | Army Builder Program
Dark Angels Codex 2013
Chaos Daemons Codex 2013
Chaos Space Marines Codex 2012

Warhammer 40k Forum Tau Online

 

Warhammer 40K Forum

Urgent C help needed!
Reply
Old 01 Oct 2009, 15:27   #1 (permalink)
Shas'Ui
 
Join Date: Jan 2008
Location: Ireland
Posts: 698
Default Urgent C help needed!

Right, I have an assignment due tomorrow. It's in C, it's fairly simple, just maths computation, except I have to print out my results to an Excel file. Have to generate a chirp signal.

I haven't done C in around a year and a half, but I've been doing Java so I know about structure/ how to think when programming.

Any tips on how to print out my results to an Excel file?

Edit: A guide to how to use the System Clock would also be handy. :-[
__________________
Click on these little dudes to get a slightly bigger little dude!




http://www.travian.co.uk/?uc=uk1
RonanB1011 is offline   Reply With Quote
Old 02 Oct 2009, 01:59   #2 (permalink)
Shas'O
 
Join Date: Aug 2006
Posts: 9,460
Default Re: Urgent C help needed!

Excel? I'd go for CSV then, and just open it in excel. Outputting comma-seperated-values shouldn't be hard. Getting all the proper headers and footers and formats for a true .xls would take for ****ing ever.

As for system clock, I think there's a very simple function like time() that gives you the time in seconds, and something like timemilis() that gives it in miliseconds- that isn't C though, its platform specific. If you're on windows, the Microsoft Developer's Network has fantastic support, with pretty much every single function in C on there.
GeekyGator is offline   Reply With Quote
Old 02 Oct 2009, 10:04   #3 (permalink)
Shas'Ui
 
Join Date: Jan 2008
Location: Ireland
Posts: 698
Default Re: Urgent C help needed!

Here's my code. Can you try and pick out the errors for me. Also, what development pack would you recommend? I'mm using Visual C++ and it's not nearly as good as Eclipse was for Java.

================================================== ================================================== ==========================================

[glow=red,2,300]// MyFirstAssignment.cpp : main project file.[/glow]
# include <stdafx.h>
#include <stdio.h>
# include <math.h>
# include <ctime>
# include <stdlib.h>

#define PI 3.141592654; [glow=red,2,300]//Define constant[/glow]

void main (){

float StartFrequency;
float FinalFrequency;
float ChirpDuration; [glow=red,2,300]//Time duration in seconds[/glow]
float IncreaseFrequency;
float CurrentFrequency;
double GraphPosition;
float Period=0; [glow=red,2,300]//Will represent time[/glow]
float StartTime=clock;[glow=red,2,300]()//Shows start time[/glow]
double AboveTheLine;

FILE file*; [glow=red,2,300]//could someone explain this procedure to me please?[/glow]
file = fopen("output.txt", 'w'

printf("Please enter the Starting Frequency of the Chirp\n");
scanf("%f",&StartFrequency);
printf ("The starting frequency is %f\n",StartFrequency);
printf("Please enter the Final Frequency of the Chirp\n");
scanf("%f",&FinalFrequency);
printf("Please enter duration of the Chirp\n");
scanf("%f",&ChirpDuration);

IncreaseFrequency = pow((FinalFrequency/StartFrequency),1/ChirpDuration);

printf("Time is %f",StartTime);
CurrentFrequency= StartFrequency;
while (CurrentFrequency<FinalFrequency && ((Period-StartTime)/CLOCKS_PER_SEC)<ChirpDuration){
Period = clock() - StartTime;
AboveTheLine = 2 * PI * StartFrequency *(pow(IncreaseFrequency,Period)-1);
CurrentFrequency = Period*StartFrequency*IncreaseFrequency;
GraphPosition = sin((AboveTheLine)/log(IncreaseFrequency));
fprintf (file,"%f", GraphPosition); [glow=red,2,300]//Something wrong here, don't know what.[/glow]
}
fclose(file); [glow=red,2,300]//something wrong with this. Don't know what.[/glow]

}

================================================== ================================================== ==========================================

[glow=red,2,300]And here's the build.[/glow]

1>------ Build started: Project: MyFirstAssignment, Configuration: Debug Win32 ------
1>Compiling...
1>MyFirstAssignment.cpp
1>.\MyFirstAssignment.cpp(19) : warning C4244: 'initializing' : conversion from 'clock_t' to 'float', possible loss of data
1>.\MyFirstAssignment.cpp(22) : error C2143: syntax error : missing ';' before '*'
1>.\MyFirstAssignment.cpp(22) : error C2059: syntax error : ';'
1>.\MyFirstAssignment.cpp(23) : error C2664: 'fopen' : cannot convert parameter 2 from 'char' to 'const char *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>.\MyFirstAssignment.cpp(39) : error C2100: illegal indirection
1>.\MyFirstAssignment.cpp(39) : warning C4552: '*' : operator has no effect; expected operator with side-effect
1>.\MyFirstAssignment.cpp(42) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE' to 'FILE *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>.\MyFirstAssignment.cpp(44) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE' to 'FILE *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Build log was saved at "file://c:\Users\RonanB1011\Documents\Visual Studio 2008\Projects\MyFirstAssignment\MyFirstAssignment\ Debug\BuildLog.htm"
1>MyFirstAssignment - 6 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
__________________
Click on these little dudes to get a slightly bigger little dude!




http://www.travian.co.uk/?uc=uk1
RonanB1011 is offline   Reply With Quote
Old 02 Oct 2009, 14:21   #4 (permalink)
Shas'Ui
 
Join Date: Jan 2008
Location: Ireland
Posts: 698
Default Re: Urgent C help needed!

Fixed the errors and now it's working perfectly.

Emergency over. 8)
__________________
Click on these little dudes to get a slightly bigger little dude!




http://www.travian.co.uk/?uc=uk1
RonanB1011 is offline   Reply With Quote
Old 04 Oct 2009, 19:38   #5 (permalink)
Shas'O
 
Join Date: Aug 2006
Posts: 9,460
Default Re: Urgent C help needed!

Visual C++ isn't bad, imho. You can check out DevC++, but its really old now...
GeekyGator is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT MEDICAL HELP NEEDED sarnas Enclave Talk 47 17 Aug 2008 12:49
Urgent Help needed with my Linksys Wireless wossname! Frosty05 Computers, Science and Technology 5 26 Aug 2007 06:39
URGENT background novel advice needed MrDakka 40K Universe 3 20 Jan 2007 16:25
Urgent help needed! sarnas Tau 17 03 Jul 2006 13:51
Urgent Advice Needed! AuinMyrrath Tau 8 18 Mar 2005 02:43