a(domain);
should be
a(Domain);
And main should return 0 on successful return. Perhaps it internally does so. But its good practice to specify them explicitly.
ssharish
a(domain);
should be
a(Domain);
And main should return 0 on successful return. Perhaps it internally does so. But its good practice to specify them explicitly.
ssharish
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
nelledawg you could clearly see from the error message what the problem with the code is. Lets have a look at your some of your error message and the solutions for that error.
Error 1: error C2660: 'total_sales' : function does not take 0 arguments
What does it say, its saying that total_sales function does that takes 0 number of arguments , which is right , because youm have prototypes the total_sales function as taking 3 arguments
void total_sales(double *m, char **cal, int c);
And you are missing some braces her and there. And you need to sit down check the function prototypes, may be will reduce a hell lot of errors.
ssharish
hahaha here we go a homewok thread again. SivaKrishana show us a snap or some of your code, that way you might get some more help. Luckychap had shown some code, which is some thing very important for your application. Have a look at it.
ssharish
It would have been more nice, to see what problem you had. May be we could learn more from that as well. Please do post the problem and the solution you came your problem. You might get some more help and perhaps some feedback on your solution.
NOTE: If you started this started them you could mark this thread as solved, if you found the solution. ;)
ssharish
As it’s been previously mentioned that, there are quite a few problems in your code. Which you might have to sit down and think about. I will point you out few error which you have made.
1.The memory allocation for char point word is not right.
Char (*word)[30];
Has to be like this
Word = malloc( sizeof (char *[30] ) * 10 );
// Please note you need to do some error checking down, to avoid further problem
2.Reading string through fgets is really a good practice, but at the same time you need to understand the on how to use those function and their parameter list. The fgets function for a void * pointer, but not .void ** pointer. Which means that, the usage of the fgets function should be as follow
fgets( word[i], 30, stdin);
To makes more for easy and, I have written few sample codes which might give you some idea on how to read string in two ways .One is through a Array of char pointer methods and the other one through pointer to pointer methods. Have a look at it. You should get some idea on how to use them.
#include <stdio.h>
#include <stdlib.h>
void readstring( char (*word)[30] )
{
int i;
for( i = 0; i < 10; i++ )
fgets( word[i], 30, stdin );
}
int main()
{
char (*word)[30];
int i, num;
printf("Enter the number of word you want to sort\n?");
scanf("%d", &num );
word = malloc( …
Here is a good tutorial on how to access with serial port. Perhaps this guy is using turbo C compiler.
Well, if you wanted to read an data format he port and write them on to the file. It should be pretty straight forward. Because all data which are received from serial port on in the format of string. Well not necessarily but you could read them as string and then write them on to file, in which ever format you want. Well for read you would use fscanf function i guess. It link shows how to do that.
But still, you should consider changing your compiler.
ssharish
sorry for being so vague, but i am just starting with this and this is my first project,
well i am using turbo C version 3
and i am developing for windows XPthanks
Well, Turbo C compiler o more supported. Try think of changing to a new compiler. Like Dev-C++. Which is really good. Perhaps if get standard libraries to access Serial port from windows. If i can still remember you have a library bios.h which allows your access serial port. Is it iport and oport.
ssharish
Compiler flag are not there to use randomly, they should used according to the requirment. Use the main page to get the complete list of compiler flags wiht the brief expplaination of it.
Some of the common one used is -Wall -W -ansi -O<x> -o -g -c -I.
ssharish
ya thanks! but wht abt multiple entries? suppose i have checked the first entry in [MARKS] and want to check the next, how to proceed for that?
Keep reading the file line by line using fgets. Check whether the read value is [MARKS]. Once you know that the read value if MARKS, you know what the MARKS tag will followed by, for example your modules marks. Continue reading the next line. And see if your have reached the line where the module you are looking for. Change the modules marks and continue reading untill you reach EOF.
And there you go you van change just as you can.
ssharish
OK, what you wanted to really do is to accept a infix express and then convert them into reverse polish express and then evaluate the express.
This is achieves using stack and Q's concept in data structures. Have you done data structure before. Get a data structure book and see the concept and of Q's and stacks. Its very easy to do with those two and perhaps can use trees as well.
And google infix and reverse polish expression if you havn't heard about them before.
ssharish
YES, it does say to prototype there
get_current_dir_name(), which is only prototyped if _GNU_SOURCE is defined
http://linux.die.net/man/3/get_current_dir_name
ssharish
Looked at your post again, and I feel that you could come up with the solution for this using the UNIX socket Sever/Client Arch. Perhaps something similar to dudeyprateek.
What you have to is run server, where is will just accept the connection from the client get the data from the client and keep on buffering the server. The server is the only contact point to your hardware. The server will keep on checking the buffer in the hardware to make sure that if it can accept any data, IF yes then you get a chunk of data from your buffer on the server and send them across to the hardware buffer. But the server will still keep on getting data from the client.
This way you can buffer the data on your machine.
> If anyone have some sample code
Its quite a lot of code to post it here. Have a go with this. See what you get along.
ssharish
OK, i guess i am with you now. So the weight machine has a display where you see the current weight, you want this value to be feed into the video display on your computer which you are at the movement doing it manually. But instead you wanted a system which can pick the value for the weight machine automatically and do some manipulation.
Well, the answer for that would be, did you get any device driver along with you weighting machine, if so they should be having some API calls, which you can call to read the values from the machine.
If you don't, try contacting your weighting machine vendor, they might having some idea, check out there website to find out if they have any facility of accessing their hardware from the machine.
ssharish
What you are after is something smilier to this.
char Buffer[20];
int count = 10;
sprintf(Buffer, "my_id_%d_", count);
To be more safer on hand use snprintf, if you are worried about overflow and all. Do the same for your send concatenation.
The above is just an sample code which would give you an idea on how to use sprintf. You will have change the variables to get used in you program.
EDIT:
And to achive what you want, either you will have to call sprintf twice or you will have use the combinaton of strcat and sprintf function calls. Like
sprintf(Buffer, "my_id_%d_", count);
count += 10;
sprintf(FinalStr, "%smy_com_id_%d", Buffer, count);
ssharish
Do C and C++ support sockets? Are any special libraries required?
YES, C\C++ support Socket/Network programming. Follow a link bellow for a good tutorial on socket and RPC programming.
Socket Programming
RPC Programming
RPCgen Programming
ssharish
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
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
First of all, the mistake you have been doing is using Turbo C compiler and getting confused between code written for MS-DOS and Windows OS. STOP using your Turbo C compile and just focus on things which are more standard.
>I want to know why the above code i mentioned is getting compiled in TC but not DEV CPP IDE >and how to make it run in DEV CPP IDE 4.9.9.2
You can already see from the error message thrown by the compile on Dev-C++. You have been using some non standard library which was available under TC. But, Dev-C++ doest support those libraries what so ever.
And now explain us, why do you need this code. What is the main purpose of writing this code? What I understand from your post is that, you trying to use this program send and receive data between your microcontroller and your PC. If that was your main intention, there is already inbuilt terminal emulator "HyperTerminal" which does that for you. Where you can transfer your binary to your MController.
If that wasn't your intention, Can you explain you what are you trying to do?
And on the other hand, have a look at the links which I posted in my previous post, there is an article on how to program a serial port for Windows. Its a good Article which was taken from MSDN. If you follow that you will be able to achieve something …
True, I think he should be getting that value from the config file rather than comand line, I think thats what OP is looking for.
ssharish
The normal approach for this problem is to read 4 lines and then read 5th line and again read 4 lines and then read the 5th line and so on. You could even use fseek but the problem with that is you should be having the right offset value. In your case to find the offset value you dunno the length of each line which going to be a pain.
I would rather suggest you to follow the first method which i said. To be honest with even the configuration files are read in the same.
ssharish
Something like this
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE **fp;
char filename[20];
int i;
fp = malloc( sizeof(FILE *) * 10);
if( fp != NULL )
{
for(i=0; i<10; i++)
{
sprintf(filename, "%s%d.txt", "file",i+1);
if( ( fp[i] = fopen(filename, "a+") ) == NULL )
{
printf("Error: File \"%s\" cannot be opened\n", filename);
continue;
}
fprintf( fp[i], "%s", "Hello There");
fclose(fp[i]);
}
}
else
{
printf("Error: No enough memory\n");
getchar();
return 1;
}
free(fp);
printf("All done\n");
getchar();
return 0;
}
This could be done using just one single file pointer. But this is to demonstrate, how allocate FILE pointer dynamically.
ssharish
Jobs you are in a right track. Thats right When do this
void foo(FILE *fp);
in main
foo (fp);
When you call foo the address of the file pointer will be copies and sent to the foo function. If you wanted to send it through reference then you will have to do something like this
void foo(FILE **);
in mian
foo(*fp);
But the first method would do what you want.
ssharish
Salem if that was possible, how can we include the .so file at run time?
ssharish
What is your hardware, where is it connected, how much memory does it have?
ssharish
Well, C supports in multi threading. But before i can say anything about light weight process. I should ask you which OS and compiler are you using.
If you are on Linux, you should looking at something called pthread library.
ssharish
Cant you use ifndef-else-endif directives?
EDIT: Run time, i wonder you could.
ssharish
>The value of an address is completely implementation-dependent to allow for such atrocities as segmented address spaces.
So you mean to say that size of the int * could vary. Thats changes from machine to machine.
And can i also say that it would normally depend on how bit machine its like 32 or 64?
ssharish
perhaps look at this one as well.
#include <stdio.h>
int main()
{
int a[10];
int *a1;
printf("%d\n", sizeof(a));
printf("%d\n", sizeof(a1));
getchar();
return 0;
}
/* my output
40
4
*/
Ancient Dragon, sizeof(int *) and sizeof(int) just gives 4 bytes. That makes size since all memory location are 4byte long, well on 32 but machine. Am i right?
ssharish
Use Dev-C++, thats good as well. Salem Thanks for that Code::Blocks that looks pretty cool.
ssharish
#include <stdio.h>
int main()
{
FILE *read, *write;
char Buffer[BUFSIZ];
if( ( read = fopen("Marks.txt", "r") ) == NULL )
{
printf("Error: File cannot be opened\n");
return 1;
}
if( ( write = fopen("TempMarks.txt", "a") ) == NULL )
{
printf("Error: File cannot be opened\n");
return 1;
}
if( fgets( Buffer, BUFSIZ, read) != NULL )
fprintf( write, "%s", Buffer );
fprintf( write, "%s - %s\n", "Name", "Name2" );
while( fgets( Buffer, BUFSIZ, read) != NULL )
fprintf( write, "%s", Buffer );
fclose(read);
fclose(write);
remove("Marks.txt");
rename("TempMarks.txt", "Marks.txt");
return 0;
}
ssharish
What i want is that when i copy/add the data that is in the buffer (in this case the read file) to be fully copied into the string. What i does now i copys the the data that is in the buffer but it thinks that it's finished once is comes accross a nullterminator '\0'. I want it to get all the data in de buffer so not stop at null termininators. It should only stop when there is nothing left to copy.
Thanks by the way for helping
OK Thats fine, So you wanted all the data from your buffer that is your read file into one single string. Narue had already posted a sample code which uses strcat. And that what you are looking for.
ssharish
Windows tent to have their own standards, but not on Unix world. And hence u find those code with uses gets and fflush function. Very interesting code.
I am sorry, i am on unix world.
ssharish
But, Lets say what you have stored in your buffer is the contents of your file that you've open,. How do you get all the content of that file into your string without it stopping after the first null.???
Sorry dint really get u when u said "without it stopping after the first null.??". Do u want the contents of the file into file string. Is that u wanted. That should be straight forward.
Clarify my question, will post a sample code
ssharish
George, nobody is going to do u'r homework. Please read the form rules before asking question. It would be more better if u could show us what have u got so far.
Do u know how the Depth First Search algorithm works. It very important u understand the algorithm before u u do anything. I have coded this is LISP, its much simplier in LISP rather than C.
I would suggest u to first go and understand the Depth First Search first.
ssharish
U can try to use function like "fflush(stdin)",when u call it ,it can also clear the input buffer
Don't use fflush to clear input buffer, it there to clear just the output buffer. Read this
ssharish
I can write a big list of comments on your code. But i dont have time for that. But just a quick review you are using quite a lot of non standard function and libraries.
What compiler are u using?
But over all good code.
ssharish
According to your subject title what i can understand is that u are trying to read data from serial and redirect it top PS/2.
Well, PS/2 are basically used for input devices, and perhaps if u wanted to read anything from there, u just access it through stdin standard input pointer as Ancient Dragon said.
Now can u make clear what are u trying to read from the input buffer and what are u trying to write on to the source. And what is your source.
What is Diskless PC?
ssharish
So the solution for that porblem is to stop using scanf function and perhaps WaltP has give you a good link on what are the function which need to avoided and it also explains about the scanf in more details so start thinking about an alter native way of reading values from the user.
Or if you still wanted to use scanf function then call the following function after every call on scanf function.
void Clear_Buffer(void)
{
int ch;
while((ch = getchar()) != '\n' && ch != EOF);
}
What this code does is just clears the input buffer, which resolved your problem.
Hope helps :)
ssharish
Thats one lot of mess, you should start indenting your code properly and perhaps what happened to your code tags. You will have to put your question properly in order to get more help. From what u have said i have come up with the sample code which will give you an idea on what need to be done
#include <stdio.h>
#define MAXSIZ 5
void PrintFloat(double []);
int main( void )
{
double num[MAXSIZ] = { 12.23, 23.42, 45.66, 67.897, 786.86 };
PrintFloat(num);
getchar();
return 0;
}
void PrintFloat(double num[])
{
int i;
for(i = 0; i < MAXSIZ; i++)
printf("%.3f\t", num[i]);
}
/* my output
12.230 23.420 45.660 67.897 786.860
*/
Dont define the function within the function. Its not a good programming practice, and perhaps u will have function scope problems which is just a mess.
ssharish
Here is a sample code which u could use or perhaps u can get an idea on how to use sscanf function to parse the string.
#include <stdio.h>
int main()
{
char str[] = "# Name: C02427.mol TAUTOMER 1 2706";
char str1[20], str2[20], str3[20];
int D, D1;
char FileName[35];
if( strncmp( str, "# Name", 6) == 0)
{
sscanf(str, "%*[^:]: %[^.].mol %s %d %d", str1, str2, &D, &D1);
sprintf(FileName, "%s_%s_%d_%d.mol", str1, str2, D, D1);
printf("Filename -> %s", FileName);
}
getchar();
return 0;
}
/* my output
Filename -> C02427_TAUTOMER_1_2706.mol
*/
Hope that helps
ssharish
i thnk fprintf() is a better option
It depends up on how u want the write the data on to file. If u think fprintf is good use them.
ssharish
i cant unzip it on my machine, just use the windows compress utility feature. Or perhaps just post the make file contents
ssharish
by trying the way as suggested by u, shall i use fputs to write the string to new file. for reading from the file and putting to string i am using fgets()
Spot on, thats right, use fgets to read from the old file. Alter the string and write the new string to the new file using fputs or fprintf if u wanted to format the string. This would be more approchable for inital.
ssharish
Is there any provision to delete some part of file?
Well u could that through fseek function and try writing few bytes. But u need to be careful through.
ssharish
I am on windows XP prof SP2. I will try what u suggested.
Thank you
ssharish
That piece of code just keeps in reating the same thing again and again for ever. I mean it just displays the same thing. U will have to update something as the game goes along. So you will have to get some input from a particular source.
And have u tried compiling and running that program. I guess u are using some 16bit complier.
ssharish
there u go a pesudocode for u
void writetofile(char *log)
{
open file
check file open status
build the log message with time and append the *log using sprintf
write log to file
close file
}
ssharish