Coreper Posted December 18, 2006 Report Share Posted December 18, 2006 ok, ill quit talking about it in this topic@jason.b.c.:LOL!!!! ill let you guys know about an update to our machine.something you guys may find interesting: our robot will be used on the open day of our school: a day when the students of the next year come and watch our school, with introductions and stuff. Quote Link to comment Share on other sites More sharing options...
jason.b.c Posted December 18, 2006 Report Share Posted December 18, 2006 ok, ill quit talking about it in this topicYou could just P.M. me and Cozofdeath..??@jason.b.c.:LOL!!!! :D Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 20, 2006 Author Report Share Posted December 20, 2006 Thanks Pat for the info. I think the static keyword is my best bet. I just looked it up on google and it sounds like what I want. Your right about declaring the memory, I didn't know how to free it. You could just P.M. me and Cozofdeath..?? :lol: Corepers gonna end up in jail :0 :lol: Five years into this revenge plot he'll be in a dirty cramped basement scattered with empty ramon noodle boxes sitting on a homemade portable toilet running a cryptic version of Linux, cracking his way threw a string of supercomputers to eventually use their all of their power to ping the kid to death. Next thing you know your getting a shower to wash the noodle stains off and, bang, a small swat team throws in a flash bang grenade and your blinded to the floor. J/k, it will probably never happen, thats why you should definitely pm us. At least let us know what happened to his computer. Quote Link to comment Share on other sites More sharing options...
jason.b.c Posted December 20, 2006 Report Share Posted December 20, 2006 You could just P.M. me and Cozofdeath..?? :lol: Corepers gonna end up in jail :0 :lol: Five years into this revenge plot he'll be in a dirty cramped basement scattered with empty ramon noodle boxes sitting on a homemade portable toilet running a cryptic version of Linux, cracking his way threw a string of supercomputers to eventually use their all of their power to ping the kid to death. Next thing you know your getting a shower to wash the noodle stains off and, bang, a small swat team throws in a flash bang grenade and your blinded to the floor. J/k, it will probably never happen, thats why you should definitely pm us. At least let us know what happened to his computer.That's Hilarious... Oh man , I almost fell out of my seat here.. A homemade toilet...!? Ha ha Ha.. :lol: Quote Link to comment Share on other sites More sharing options...
Coreper Posted December 20, 2006 Report Share Posted December 20, 2006 lol, this isnt going anywhere.. :lol:we are almost doen with building our robotPM me if you got any good ideas[cozofdeath, didnt you get my reply? yet?] Quote Link to comment Share on other sites More sharing options...
Coreper Posted December 20, 2006 Report Share Posted December 20, 2006 <sorry, this post was made by accident> Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 20, 2006 Author Report Share Posted December 20, 2006 A homemade toilet...!? It sorta went with the picture I found. I couldn't find anything else, but I like your pic better. Its a true portable toilet if I ever saw one.Hey Coreper, does that sfx (installer) file have anything to do with this? Yeah I did get your message but I sent you one back. It really can't be done remotely but I said some other good things if they got to you.I haven't studied that much C because I've been stuck on one simple program and I refuse to go on without getting it to work. Its a simple string reverser. You enter a string and it reverses it and displays both back to you. But I threw in pointers where ever I could and arrays so I could work with them more (hence the problem). I have just figured it out THANK GOD! There were 2 problems. 1) Returning the pointer. 2) I used strlen() to get the length of a string for my for loop, but I didn't account for how arrays start at zero and strlen() starts at one. 1) Pat solved with static keyword. 2) Dev-c++ debugger made me realize what was going on. Anyway heres the code (I know its very simple but I'm not the brightest crayon in the box).#include <cstdlib>#include <iostream>using namespace std;char *strReverse(char *original);int main(int argc, char *argv){ char array[20]; char *mystring, *done; mystring=array; cout << "Enter a string: "; cin >> array; done=strReverse(mystring); cout << "\nOriginal String: " << mystring << "\nReversed String: " << done << endl; system("PAUSE"); return 0;}char *strReverse(char *original){static char array[20]; // Was "char array[20]"int i, b=strlen(original)-1; // Was "b=strlen(original);for(i=0;b!=-1;i++, b--) // Was "for(i=0;b!=1;i++, b--)"array[i]=original[b];array[i]='\';return array;}btw Beef Ramen noodles rock, so do the chicken and shrimp. Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted December 21, 2006 Report Share Posted December 21, 2006 So does it work correctly now?You did not invite my comments, but I'll give some anyway. The one thing that I really don't like is the passing of a locally defined variable back to a higher-up function (the result array). It works, because it is declared 'static', but it is not "good" writing. How would I have done that part?One thing we need to understand first is that the result of a function does not need to go through a 'return' statement. The 'return' statement is "normally" used to return a status code, such as 0 for OK, or any positive or negative error number.To return one or more results, pointers to the result areas should be passed down as arguments, and the result(s) should be placed into these areas. In your case the result area is a single character string, and it should be declared in the main function, and a pointer to it passed down with the call to strReverse().A very, very light criticism is about your light use of blank space, making the code relatively hard to read. In the main function you nicely indented the code, in the subfunction not. Try to be consistent with formatting. Also use spaces between operands and operators, e.g. (your code)for(i=0;b!=-1;i++, b--)vs.for (i = 0; b != -1; i++, b--)P.S. I personally like Curry Ramen: Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 21, 2006 Author Report Share Posted December 21, 2006 You did not invite my comments, but I'll give some anyway. rolleyes.gifSorry. All comments are welcome from anyone on all source code I post. Thanks for the comments by the way. Its good to see another Ramen noodle lover. :D But I do agree with you 100% on the string reverse code. The only reason I did it that way was to learn about pointers and arrays, specifically returning a local pointer from a function. If I were to do it now I would make it like you suggested or with the string class. The spaces a do need to work on as well as commenting. Half of the time I don't even out the rest of the code. Where should I go after learn the basics? Standard Library? Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted December 22, 2006 Report Share Posted December 22, 2006 Where should I go after learn the basics? Standard Library?I would try to write another function - how about strSort() ? Pass down both source and result string pointers. Make use of explicitly allocated memory (malloc) and don't forget to free it.When you declare a string, take into consideration if it will only contain ASCII characters (0x21 ~ 0x7E), or also characters outside the ASCII range (0xA1 ~ 0xFF), e.g. European accented characters, or special signs like ¥, ©, ®, ¶, ½, etc. In this case you must declare the string as 'unsigned char', otherwise the leftmost bit will be regarded as negative sign.Hmmm - strSort may be a little complicated; I will try to think of something more simple before leaving today. Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 23, 2006 Author Report Share Posted December 23, 2006 Do you mean if I have a 5 character array of "deabc", it will get sorted to "abcde"? Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted December 23, 2006 Report Share Posted December 23, 2006 Exactly, and actually it may not be as complicated as I first thought. Try it! Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 23, 2006 Author Report Share Posted December 23, 2006 #include <cstdlib>#include <iostream>using namespace std;char *strSort(char[]);int main(int argc, char *argv){ char usrString[20], *pointer; cout << "Enter a string: "; cin >> usrString; pointer=strSort(usrString); cout << "Sorted string = " << usrString << endl; system("PAUSE"); return 0;}char *strSort(char sortme[]){ int a, b, c=strlen(sortme); char temp; for(a=0, b=1; c != 0; c--) { for(a=0, b=1; b != strlen(sortme); a++, b++) { if( sortme[a] > sortme[b] ) { temp = sortme[a]; sortme[a] = sortme[b]; sortme[b] = temp; }}}return sortme;}Comments are very welcome on this. I believe there is a better way to make this I just don't know how. I could of maybe added a toupper()/lower function so it could handle uppercase with lowercase, but it will sort all lowercase and decimal numbers but not a mix because of the difference in ascii codes. Also, I had to retype this from a notebook, because I use it for mostly programming, so there may be some spelling mistakes. I really don't know to many C functions because the book I'm reading mostly introduces C++ stuff. But there seems to be many useful ones so I'll have to check them out more, like malloc. I really should of went over C before starting C++. I was thrown for a loop a couple times making this. It was fun trying to make it though. Anymore ideas? Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 23, 2006 Author Report Share Posted December 23, 2006 I just found a good list of C++ functions on the net and got this to work. Its a lot shorter but I feel like I cheated because the Standard Template Library provides the all ready made functions. #include <cstdlib>#include <iostream>using namespace std;int main(int argc, char *argv){ char buffer[50]; cout << "Enter a string: "; cin >> buffer; sort(buffer, buffer+strlent(buffer)); cout << "Sorted string = " << buffer << endl; system("PAUSE"); return 0;}It acts just like the other sort I made. The output is sorted like this...Enter a string: zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210Sorted string = 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted December 25, 2006 Report Share Posted December 25, 2006 Its a lot shorter but I feel like I cheated because the Standard Template Library provides the all ready made functions.It's good that you made both versions but at the end the second version is better, because you left the standard work to be done to an existing function.Yes, I would say it's a good time to have a look at the available standard library functions. Find how to make conversions between datatypes. Also check how to use memcpy(), memcmp and memset(), as well as other memory functions. I find them much more useful than the string functions.One reminder: when using character arrays (and you know it's going to contain character data, not numbers), try to always declare them as unsigned char, because you never know what its contents are going to be. By default char is signed, and any character that has the high-order bit x80 set will compare negative. Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted December 27, 2006 Author Report Share Posted December 27, 2006 Awesome info Pat. I never really thought of that. I will add that to some of my source code and check the mem functions out. Right now I'm working on creating my own string class with the methods/functions...strCompare strSort strScroll - scrolls a string in any location but doesn't stopstrReversestrCountstrRot13 - adds 13 to every char to "cipher" the stringstrToArrayarrayToStrstrElite - makes 1337 stringsstrUpperstrLowerstrInverseThe rest you can pretty much tell what they do. I'm very interested in learning the built in functions, I didn't realize there were so many useful things, but I'm trying not to use them in these and keep to the basics. I also didn't realize c and c++ are so diverse. Its hard to get away from c functions. Quote Link to comment Share on other sites More sharing options...
Coreper Posted January 8, 2007 Report Share Posted January 8, 2007 if i may ask: what kind of thingys are you making?: i read things about inverting letter orderanother thing: would it be possible to create a program which pauzes your whole system, and allows you to view all running processes and such. could it then also allow you to pick one process, and only run them, while the rest is pauzed? Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted January 9, 2007 Report Share Posted January 9, 2007 if i may ask: what kind of thingys are you making?: i read things about inverting letter orderIt's just sample programs for C training.another thing: would it be possible to create a program which pauzes your whole system, and allows you to view all running processes and such. could it then also allow you to pick one process, and only run them, while the rest is pauzed?I am not sure that you can pause your entire system (all processes, including Windows services). But examining all processes is possible, and you could also raise or lower processes' priorities. You would have to look through all system functions in C++ to find out how to achieve this. Probably a bit more complex than sorting ASCII characters... Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted January 9, 2007 Author Report Share Posted January 9, 2007 Yep, just functions for learning. Functions just wrap up code designed to do a specific task. There very useful and help clean up your code. But unfortunately I have had the functions done for some time but didn't even complete the class (a group of code sort of like a function but more powerful and is used for object oriented programming). I've slowed up on C, well more like stopped for the last several days. I plan on continuing it soon though. I just haven't been able to compile it all because of errors and don't want to stare at it any longer. I'll probably get back to it soon, hopefully. Well maybe...yeah....definitely....sure...ok...thats what I'm going to do. No really I'm going to. Hows the robots coming along? Quote Link to comment Share on other sites More sharing options...
Coreper Posted January 9, 2007 Report Share Posted January 9, 2007 thanks, the robot is doing well i think ;) we will start working on it this wednesday [last 2 weeks we didnt work on it because we had vacation]i dont know if i already told this: i made a few programs for my calculator [TI-84 Plus]!the biggest, and most used [by almost every student of my year] is in dutch, but if you want to see it, i can upload itthe biggest includes a program with all kinds of formulas and help thingys in itim currently adding some content, so if you want to see it, i will upload it as soon as it is done [will take 2 or 3 days :) ]another program i made counts to 100, then to 0, then to 100, etc, etc, until you press the exit buttonanother program i made keeps counting until it makes an memory overflow [if you get a number like 1*10^100]and another program does some matrix styled thingy [displays very much numbers repeating and repeating] :Dtell me if you would like to see them Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted January 9, 2007 Author Report Share Posted January 9, 2007 If there not super big or really complicated post them. I'd like to see what they look like. I haven't used one of them calculators for a while. How do you compile and get the program in the calculator? Quote Link to comment Share on other sites More sharing options...
Coreper Posted January 10, 2007 Report Share Posted January 10, 2007 you can compile programs on your calculator or with this rocking program: TI Graph Linkyou can send programs to your using a USB to TI-83 cable [its supposed to be included with your calculator] and this connection program: TI Connecti included my files as the original TI-83 format [.8xp] and as a .txt file [easy to edit :D]note: my school program is dutch, i dont know if you guys understand thatbtw: the TI-83 programming is not hard at all [i think] {as far as i know}note: the TI-83 and the TI-84 support the same data files and stuff [use the same programming language]btw: i didnt inlcude the codes, because then my post would get way too long Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted January 10, 2007 Author Report Share Posted January 10, 2007 Its very hard to understand. But interesting to look at. I looks like you worked hard on the school.txt file. How did you learn how to do this? Quote Link to comment Share on other sites More sharing options...
Coreper Posted January 11, 2007 Report Share Posted January 11, 2007 yes i did work hard on the school programi learned by looking at other programs and trying things out myself > the best way to learnif you want to learn it to, just tell me what you need to know Quote Link to comment Share on other sites More sharing options...
cozofdeath Posted January 11, 2007 Author Report Share Posted January 11, 2007 Thanks for the offer. I was just wondering. I can barely keep my mind on C, plus I hate math and calculators in most cases. But when I was in math class a while ago I would always mess with my calculator and its functions and I remember looking up games for it but I never found a way to put them on. Its very interesting what you can do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.