Tuesday, July 14, 2009

C Programming Experts! HELP!!!??

Is this code right to recieve a text file from the specified location?? I have the code to send the file working properly.





/* Filerecive.c * * * * * * * * * * * * * * * * * * * * * * * * * */


#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


#define CNTRLZ 0x1A


int main(void) {


FILE * fp;


FILE * dp;


int c;


if ((fp = fopen("C:\\TEMP\\text.txt", "r")) == NULL) {


printf("fail to open data file\n"); return 1;


}


if ((dp = fopen("COM2", "r")) == NULL) {


printf("fail to open COM port\n"); return 1;


}


while ((c = fgetc(fp )) != EOF) {


fputc( c, dp);


}


fputc(CNTRLZ, dp);


fflush(dp);


fclose(fp);


return 0;


}

C Programming Experts! HELP!!!??
hello,





can u paraphrase your question? is this for receiving data from a port and saving to a file or are u telling us there is a problem with the file opening part but the send data by com is working?





Anyways, .... i am not so sure with my answer but :


1. fopen("C:\\TEMP\\text.txt", "r") -%26gt; fopen("C:\\TEMP\text.txt", "r")





if this is for saving the data from a port it should be :


1. fopen("C:\\TEMP\\text.txt", "w+")


2. while ((c) != EOF) {


c = fgetc(dp); /* get from port */


fputc( c, fp); /* write to the file */


}


3. also try to add : fflush(fp) just before close :)





I hope u can clear out your question so we can help u better. good luck and merry christmas in advance.





=)
Reply:hello,





Just post away here on yahoo answers, i think many experts are here in yahoo answers, so they too can help u out =). Whenever time permits, I will check your questions out as soon as I can and assist you. I apologize sincerely for not giving out my mail.





Thanks and hope I can be of service. Report It



C&C cage needing better support for rabbit and guineas?

Okay, I have a double layer Guiena pig cage, that is shared with my rabbit. I used C%26amp;C cage ideas, and used targets storage cubes. It is 5 across, and 2 on the side. it's relativly large, and eventually I will go bigger. Until that time can come, I need some advice on better support for this cage. The corner clip and ties are used for support. They work fine, however over time things are starting to become bowed or loose. I have wooden supports going through the top of the first layer, to support the rabbits hopping around. There is a ramp as well than comes up and down, so that the rabbit and guinea's can have their own 'domains'. They get seperated during night,feeding, and when i'm not here. Some days too, both animals are moody LOL. I just need some advice from C%26amp;C builders, on good ways for support ing the cage better.


Thanks!

C%26amp;C cage needing better support for rabbit and guineas?
I do have suggestion on C%26amp;C cages. However, I will not give advice to someone who is willingly putting thier pig in danger by keeping him with a rabbit. One kick (not necessarily from aggression) can kill your guinea pig.
Reply:wow well my c%26amp;c cage comes apart a lot wich is bad so i just put would so they dont i dont get it but dont know
Reply:you can go to the c%26amp;c also keep them together because rabbits and guineas get along well and rabbits don't do well together alone.
Reply:First of all remove the rabbit, I strongly disagree with keeping them together.


Secondly why dont you visit the C%26amp;C forum I am sure they will be willing to help you... http://www.guineapigcages.com/forum/





I have a large 5 x 2 c%26amp;c for my 6 pigs but its only a single level.

calling cards

Factor the expression A3(B-C) + B3(C-A) + C3(A-B)?

Hint 1





Note that the expression is zero if B = C, or if A = C, or if A = B. This means that B - C, C - A, A - B must all be factors. If you factor these out, what is left over?


Hint 2





There are a couple of ways to find the remaining factor. The brute-force method is to multiply out the original expression, use polynomial long division to take out the known factors, then see what is left over. But there is another way you can reason out the remaining factor. Look at the symmetries in the original expression and in the known factors; what do they tell us about the remaining factors?


Hint 3





The original expression has a circular symmetry in A, B, C; that is, if you substitute A for B, B for C, and C for A, you get the same expression over again. If you make this substitution in the known factors (B-C)(C-A)(A-B) you also get the same expression over again. Therefore what?

Factor the expression A3(B-C) + B3(C-A) + C3(A-B)?
Given expression


=a^3(b-c) +b^3 c-b^3 a+c^3 a-c^3 b


=a^3(b-c) -(ab^3-ac^3)+(b^3 c-bc^3)


=a^3(b-c)-a(b^3-c^3)+bc(b^2-c^2)


=a^3(b-c)-a(b-c)(b^2+bc+c^2)+bc(b+c)(b...


=(b-c){a^3-a(b^2+bc+c^2)+bc(b+c)


=(b-c)(a^3-ab^2-abc-ac^2+b^2c+bc^2)


=(b-c)(b^2c-ab^2+bc^2-abc-ac^2+a^3)


=(b-c){b^2(c-a)+bc(c-a)-a(c^2-a^2)


=(b-c)(c-a){b^2+bc-a(c+a)}


=(b-c)(c-a)(b^2+bc-ac-a^2)


=(b-c)(c-a)(bc-ac+b^2-a^2)


=(b-c)(c-a){c(b-a)+(b+a)(b-a)}


=(b-c)(c-a)(b-a)(c+a+b)


= -(a-b)(b-c)(c-a)(a+b+c)
Reply:A3(B-C)+B3(C-A)+C3(A-B)


=AB3-AC3+BC3-AB3+AC3-BC3


= 0 Answer


C#, C or C++?

I have some expirience in VB6 (ok, lots of it) and now I'd like to move on. But I cant decide between C++,C and C#. Probably because I don't know the difference :D


Please, recommand me what to do, and tell e why you think so...

C#, C or C++?
The easiest transition will be to C#. There is no memory management required in C#... C and C++ require you to be much more cautious with memory use.





VB6, though not quite a fully object oriented language, for all intents and purposes can be consider such. C++ is also, though a fully object oriented language (including polymorphism, overloading, etc. etc.).





With C, you lose the convenience of object oriented-ness (is that even a word). If you're looking for a seemless and quick transition, jump to C#. If you're look for a steeper learning curve go to C++. As for C... well... I say if you know C++, you can pretty much say you know C - just scrap all the object oriented-ness and learn structures a little more deeply.





Note: C# takes care of the memory management piece for you with something called a garbage collector, C and C++ you'll have to be your own garbage collector.





The Data Analyst - http://www.squidoo.com/thedataanalyst
Reply:depends on what you career goals are, it you are looking into game programming, embedded system etc go with C++





application programming, business objects, web development, go with C#
Reply:C#





c is the oldest one, then c++ makes it object oriented. virtually all programs for the last 10-15 years were written in c++. then the new one is c#. it is a lot easier than c++. if you are just starting choose c#!
Reply:I'd reccomend C++ and Objective C. These programming languages are very widely used, but I don't know about C#. As a Mac user, I've (unsuccessfully) tinkered around with Xcode, and once I get the Objective C down I could make a good app.
Reply:start with C then move to c++





good luck





cheerz,


Steven
Reply:I would recommend you look into Java instead. Most apps web/desktop are moving towards been created in Java. C++ is a bit dated.
Reply:I would say go with C#. I have been messing with it for about a year. Most of the books i have give examples in VB6 and C#. Looking at the examples...the only thing really different with them is wording for certain things. So you should be able to pick it up really quick. Plus C# is the newest of the others listed. It is out in a 3.0 release that is actually pretty sweet. Lets you do all kinds of really neat things. C# 2.0 runs off of the .NET framework 2.0 and C# 3.0 is built around the .Net framework 3.5 which is what Vista was built on.
Reply:See c or c++ are different from c# .I suggest you to first put your hands on c if you know basics of c then you can switch over to c# .You should not have to do c++.


There is no comparison in c,c++ or c# but a little knowledge of c is must.After c you can do c#. there is nothing common in between c and c#.


C++, Visual C++, or Java 2, HELP, I Need Guidance, No this question is not hard to answer, so just look please

bla bla bla bla bla...


Im very smart, but I need Your help, what should I learn C++ Visual C++ or Java 2.. I would Like to build programs with color, GUI's thats "Graphical User Interfaces" People.


Nice Little Programs that have fancy little buttons, .I know HTML, JavaScript and a lil bit of Java 2 and C++, but I need a lil guidance, HELP !!!! omg, Id like to start programming somtime tonight, and im sure once i have a good grip on C++ or Java 2, that Ill run with it, so point me in the right direction and ill be on my mary little way, give me what I want and ill go away... lol, j/k, I need help I need some guidance, I need help, Im not stupid, but I am a little lazy. Im usally use to just putting words images, tables, videos, mp3 music players, and all that crap on sites, but i would like to start some serious programming, like network programms, that make it possible for remote access, no im not a hacker, and no I will not turn out to be a hacker, that I know of, but just respond..

C++, Visual C++, or Java 2, HELP, I Need Guidance, No this question is not hard to answer, so just look please
If you're lazy then simply put, pick Java. It can't get easier to make GUIs in a blink of an eye.


For C++, you need a GUI Toolkit, like WxWidgets


http://www.wxwidgets.org/


Which is more complicated and will require more perseverance.
Reply:The first thing you need to do is to remove caffeine from your diet. The second is to not use terms like omg.


C++ Decimal Number Problems(Im using a database with this C++ progrm) PLEASE HELP?

Im using c++ to build a program to view a datatbase and creating queries. I have a feild in the database that contains numbers with decimals and when i view the database in c++ (via a DbGrd) there are like 30 numbers after the decimal. How do i get c++ to just show the number and 2 decimal places? I have also tried setting the number on decimal places in the actuall database to 2 but in c++ it still shows loads of numbers after the decimal place. e.g. 0.31534534543534 when all i need it to be is 0.31. Any help would be great thanks

C++ Decimal Number Problems(Im using a database with this C++ progrm) PLEASE HELP?
You can format the output of cout like this:


cout %26lt;%26lt; setprecision(2) %26lt;%26lt; yourVar %26lt;%26lt; endl;





And if you want it to show the decimal even when it is .00, use cout %26lt;%26lt; fixed %26lt;%26lt; ...





And while we're at it, if you want to make your output even prettier, you might want to make use of setw(), setfill(), and left/right...





Oh, and to use any of those, you need to #include %26lt;iomanip%26gt;

pokemon cards

C++ Programmers!! help!!?

there's an error in this code... can you help me repair it?!








#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;string.h%26gt;





void initval();





int chars[255];





int main()


{


FILE *file_r;


int ferr = 0, i;


char filename[50];


while (ferr == 0)


{


system("cls");


printf("Enter file name: ");


gets(filename);


file_r = fopen(filename, "r");


if (file_r == 0)


{


printf("Error! File does not exist!");


getch();


}


else


{


ferr = 1;


}


}


char *r;


char c, ctr = 0;





while ((c = getc(file_r)) != EOF)


{


ctr++;


}





fclose(file_r);


file_r = fopen(filename, "r");





char string[ctr];





i = -1;


while ((c = getc(file_r)) != EOF)


{


i++;


string[i] = c;


}





printf("\n%s", string);





printf("\n\n%s\n\n", strrev(string));





//tig-ihap





for (i = 0; i %26lt; strlen(string); i++)


{


chars[string[i]]++;


}





for (i = 0; i %26lt; 256; i++)


{


if (chars[i] != 0)


{


printf("%c = %d\n", i, chars[i]);


}


}





getch();





fclose(file_r);


return 0;


}





void initval()


{


int i;


for (i = 0; i %26lt; 256; i++)


{


chars[i] = 0;


}


}

C++ Programmers!! help!!?
do this:





char [] string = new char [ctr];








and don't forget





delete [] string





at the end to free up the memory
Reply:from the code you provided i copy and paste it on my system and i recieved no error messages and the program ran fine most likely it has to do with your compiler in my unix based system it didn't recongize the conio.h header file try using a different compiler
Reply:you cant declare a char string that way (char string[ctr]). the length of the string has to be a constant size such as "char string[20];". as the other person said, you could also do this "char [] string = new char [ctr];"
Reply:The code you're using isn't C++, it's just C. It'd help if you listed the error.