ssharish2005 62 Posting Whiz in Training

As everyone else had pointed out solution for, it better to you scanf function to read string or to reading anything at all. At least that my preference. But anyway, if you still used it make sure you flush the input stream before the second call of scanf function. The following code would help you in flushing the input buffer

void clear_buffer( void )
{
     int ch;
     
     while( ( ch = getchar() ) != '\n' && ch != EOF );
}

~ssharish

ssharish2005 62 Posting Whiz in Training

You could also do something like this. Where you return the memory address of the allocate space in heap.

#include <stdio.h>

int** allocate_matrix(int rows, int columns);

int main() 
{  
    int **table = NULL;  
    
    table = (int **)allocate_matrix(3, 3);  
    
    getchar();
    return 0;
}

int** allocate_matrix(int rows, int columns) 
{
     int i, **table;
     
     table = malloc(rows * sizeof(int *) );
  
     for (i = 0; i < rows; i++) 
         table[i] = malloc(columns * sizeof(int));
         
     return table;
}

And of course, dont forget to do some error checking there! Which is very important

~ssharish

ssharish2005 62 Posting Whiz in Training

#define GCD(); Take of that semicolon from that statment. Macros donst need a semicolon. If your marco definiation are like too big then you might use a '\' to speak it up and concatenate.

But for you just the semicolon off.

ssharish

ssharish2005 62 Posting Whiz in Training

A bytecode is set of instruction which is generated the by a java compiler. This bytecode can then be ported to any machine regards of the on what platform and processor architecture of the target machine is! The bytecode will then be interpreted by the Java Virtual machine (JVM) which then internally creates a binary which can then be executed by the local machine or whatever the processor architecture which the local machine has been implemented. The JVM holds the complete system spec. So that when it interprets the byte code it knows on what platform its working and what sort of binary it has to produce.

But when we speak about binary, it is something which the compiler generates it for us. When you compile a C code by a C compiler, example GCC, it created .exe file or a binary file which can then be executed. The GCC doesn’t create byte code instead it creates a binary. But what you should remember is that, when you compile your code for your embedded system, you should compile your code to get the binary which can then be executed by the processor which is there on the embedded board but not our host machine.

Because those both are completely different in terms of processor architecture. But thanks for the GCC. It can create binary for a wide range of processor. And hence it’s called native compile. The compile which can generate binary for specific processor architecture is called …

Alex Edwards commented: Thanks for the clarification! +1
ssharish2005 62 Posting Whiz in Training

In addition to what Ancient Dragon said, YES java can be used to program some low level devices. As far I know it is quite used in the mobile programming and in Bluetooth and many others. Well what you need to understand here is the fact that they are all running on a specific platform. You write a program using java for a mobile device and the program get compile to generate a bytecode which is then interpreted by the Java Virtual Machine (JVM). You can clearly see that the target device should be installed with the JVM, which it does on most devices.

Now, let’s think it practically with the ATMEL AVR board. These boards come with the AVR microcontroller which has a very small amount of memory. We are speaking in KB’s. We use several techniques to improve the efficiency of the code to make use of the memory effectively. When it comes to ATMEL we are speaking of three types of memory flash, SRAM, eeprom.

The ATML AVR board doesn’t come with any RTX or RTOS with it. The only software which gets shipped is the boot loader. It doesn’t come with JVM. The JVM its self needs a specific platform to run which the AVR doesn’t support (I might be wrong).

And more over java doesn’t support pointers, and for programming an embedded system you need pointer. Since I don’t program java I am not pretty sure about it. I think its some …

Ancient Dragon commented: Very nice explaination :) +32
ssharish2005 62 Posting Whiz in Training

Pleaseeeeeeeeeeeeeeeeee use code tags :'( and intendant the code.

ssharish

Salem commented: I hear that! +18
ssharish2005 62 Posting Whiz in Training

Have a look at a function calle3d fgets which is defined under stdio.h library. This function will do what excatly you want. It read a line of text from the text file until it EOF which then return NULL. The sample usage of that function can be found bellow

FILE *fp;
char buffer[BUFSIZ];

if( ( fp = fopen( <filename>, "r") ) != NULL )
{
    while( fgets( buffer, BUFSIZ, fp) != NULL )
           printf( "%s", buffer );
           /* You could backup this buffer
              by copying it on to a different
              char array */
}

ssharish

jephthah commented: simple +4
ssharish2005 62 Posting Whiz in Training

ohh nelledawg, where did you get the code from. It donst look like that you wrote the code. You need to look into some basic before you program anything like this. You are usinfg some advance pointer types which you need to under stand. Let me should a simple example on how to send arguments. Look at the following code. And arguments is something which you send it a function. These values will then we used in the function for it own processing. So might have been decided for that function does and you should be knowing needed to be sending. So for example

int sun( int a, int b);

The above ius function which takes two integer arguments a & b. Now i know that function takes two integer argument and it works on that two argument. So when I call that function i call it through this way

sum(1, 2);

or 

int a = 10;
int b = 20;

sum(a, b);

Now sit down and look at your code and see what arguments should be sent to the total_sales function.

ssharish

jephthah commented: good call. I think you're right. he didnt write this code, did he? +4
ssharish2005 62 Posting Whiz in Training

Well, ok i decided to give you hint but not the answer, here you go with some sample pesudo code. This should give you an idea on how to approch this problem.

character [] source = " We dont do your homework "
charater [] destination;

Fetch each char from the source array 
      Check if the fetched char is white space char
            if so continue the loop
      if not space char
         copy that char into destination 

print the destination ( with no white space in it )

ssharish

Luckychap commented: Nice pesudo code +2
ssharish2005 62 Posting Whiz in Training

Do you mean that I can send a value from a function written in one language to the main function written in another language using sockets? I'm new to the concept of sockets.

YES thats right, you call the routine which is written in a different language. But the calling procedure is language independent. It will vary from language to language. But, in LISP you have a inbuilt library which allows to do some socket manipulation.

I don't know what is RPC and RPCgen . Are these related to sockets? From what you've given it seems it is related to networking.

YES, it is something related to networking. But its is more often used in the UNIX world. I dunno about this on Windows though. I will have to research. RPC stand for Remote Procedure Call. So the name itself specific what it is suppose to do. You register all your routines on the server and the server will be waiting for the connection from the client and when once connected the client will request for a routine to be executed and the server will execute it and sends back the results to client across the network. Goggle "RPC Programming". This comes under a topic of Distributed Computing

ssharish

Jishnu commented: Thank you once again :) +2
ssharish2005 62 Posting Whiz in Training

I had a problem which is something similar to what you are having, on how to interface the AI routine with my Code. But in my case the AI reasoning part part was done LISP. So for example if an Agent wanted to move from a point A to Point B there could be different path, which basically depends upon environment.

The LISP routine would normally find the path for me, the output of that function (Which is nothing out the path) will be sent to my C code using sockets.

You could use sockets to communicate between routines if your wanted. Which makes it more simple, some thing similar to RPC or RPCgen which you are requesting for a routine to be called on the server and the output of that function would directed to the client to the client.

Some alternative for you

ssharish

Jishnu commented: Great Help :) +2
ssharish2005 62 Posting Whiz in Training

Use Dev-C++, thats good as well. Salem Thanks for that Code::Blocks that looks pretty cool.

ssharish