Help in making a c program to a nds file

support for the ARM toolchain
Post Reply
frankeinsteinp6
Posts: 1
Joined: Sat Dec 06, 2008 5:30 pm

Help in making a c program to a nds file

Post by frankeinsteinp6 » Sat Dec 06, 2008 5:47 pm

I'm kinda new here so please, i'd appreciate any help

I need help making my program run in my "Developer's System".

I've installed devkitpro and managed to "make" some examples and run them.
The problem is, i don't know how to make my own program run.

This is a code to determine which is the fastest program among the two other programs.

This code, is a C program works when i compile it with Dev C++, but it is restricted when i command make.
Too much errors it says and i don't know how to debug it :cry: .

Code: Select all

#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
#define size 1000

int maximum (int x, int y)
{
    if (x < y)
        return y;
    return x;
}
 
       main(){
           
              int X[size];
              int MaxSoFar = 0, Sum = 0;
              int L, I, U;
              int i;
              
                     srand(time(NULL));
                     
                            for(i = 1; i < size; i++)
                                 X[i] = rand() % 201 - 100;
                                 
                            clock_t startTime = clock();
                            
                                    for(L = 0; L < size; L++)
                                        for(U = L; U < size; U++)
                                        {
                                            Sum = 0;
                                        for(I = L; I <= U; I++)
                                            Sum = Sum + X[I];
                                        MaxSoFar = maximum(MaxSoFar, Sum);
                                        }
                                    clock_t endTime = clock();
                                    
                                        printf("\ntotTime (in ms): %d", size * (endTime - startTime) / CLOCKS_PER_SEC);
                                        printf("\nSum : %d", MaxSoFar);
                                        
                                            getch();
                                        }
i know it needs an #include<nds.h> , but thats all i know.
BTW, the running time of the program depends upon the value of *SIZE*.
I need to learn how to code on the DS so that i can leave it on overnight and save electricity.
This is for our subject - data structures.
I've been getting sleepless nights from this. :x

O, if i missed any details, kindly inform me. I'll reply by tomorrow. I've gotta get some sleep 8)

opearn
Posts: 23
Joined: Tue Feb 17, 2009 11:29 am

Re: Help in making a c program to a nds file

Post by opearn » Tue Feb 17, 2009 12:14 pm

soo... you have not edited the code at all? yet you expect it to work?

first thing i notice is the lack of an infinite loop. this means your even newer at C++ than i am. this makes me happy.... enough to help you out.

when you compile you should get the following errors:
___________________________________________________________
c:/devkitPro/hello_world/source/main.cpp:8:19: warning: conio.h: No such file or directory
c:/devkitPro/hello_world/source/main.cpp:20: warning: ISO C++ forbids declaration of 'main' with no type

c:/devkitPro/hello_world/source/main.cpp: In function 'int main()':
c:/devkitPro/hello_world/source/main.cpp:44: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
c:/devkitPro/hello_world/source/main.cpp:44: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
c:/devkitPro/hello_world/source/main.cpp:47: error: 'getch' was not declared in this scope

____________________________________________________________

now you need to fix these errors, the problem is that this code needs to be edited.

Error 1.
"Conio.h", did this file come with your source? if so it needs to be put in your project.
and if you wan't my help then put that code up as you have done with your main.cpp,
*EDIT* Google tells me that its a runtime file for "conio.h is a header file used in old MS-DOS compilers to create text user interfaces"

Error 2.
ISO C++ forbids declaration of 'main' with no type,
to call Main you should replace your "main(){" with "int main(void) {"

Error 3/4. (are the same)
%d calls the wrong variable type,

Error 5.
Replace "Getch();" with "getchar();"

Now its Compilable!!!!
although error 3/4 needs to be fixed, and i'm not sure if this will even work without an infinite loop...

what is this code even meant to do?

oh and one last question how would leaving your ds on overnight save electricity?
you may call me sceptic but, i really doubt that it could.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests