Sunday, August 2, 2009

C++ c language?

Assume that you are required to enter a list of strings into a computer, rearrange them


in alphabetical order, and then print out the rearranged list. The strings must be stored


in a two-dimensional character array. Each string will be stored in a separate row


within the array. You may use any suitable string manipulation functions. One of the


library functions that can be used is strcmpi.


strcmpi compares the strings but does not differentiates between upper and


lowercase characters. The function accepts two strings as arguments and returns


integer value, depending on the relative order of the two strings, as follows:


a) A negative value is returned if the first string alphabetically precedes the second


string.


b) A value of zero is returned if the first string and the second string are identical.


c) A positive value is returned if the second string alphabetically precedes the first


string.


If the function strcmpi (string1, string2) returns a positive value then, this


indicates that string2 must be placed ahead of string1 in order to rearrange the


two strings in alphabetical order.


6


Sample output is given as follows:


Enter each string on a different line:


Type ‘END’ when finished


String 1: Panda


String 2: Apple


String 3: Island


String 4: Calendar


String 5: Brown


String 6: Black


String 7: Rainbow


String 8: News


String 9: Ballroom


String 10: Canada


String 11: END


Reordered list of strings:


String 1: Apple


String 2: Ballroom


String 3: Black


String 4: Brown


String 5: Calendar


String 6: Canada


String 7: Island


String 8: News


String 9: Panda


String 10: Rainbow


String 11: END

C++ c language?
Is this just to make someone else do your computer science homework? Never going to become a programmer like that.





Anyway, you should do the following:


1. Assign a second array with the "values" of the words (perhaps a float to store multiple letters)


2. Sort the second array, mirroring your actions on the original. Use quicksort if you can.


3. Say "w00t!"
Reply:What is your question?

send flowers

Where can I read C.L. WIlson's "Lord of the Fading Lands" online for free???

I have been waiting for this book to come out in my library but it's not there. If you know of a site I can go to to read this book, please let me know. And please don't tell me to buy the book b/c I am only 16, meaning:


-I have no $$$.


-i can't drive anywhere.


-i can't buy online.


-i don't have a library card even if it does come 2 my library (my mom canceled it!)





so please help me! i feel like i'm having withdrawal symptoms...


Where is the best page to learn C+ free?

http://library.thinkquest.org/19436/intr...


I am looking something similar for c+

Where is the best page to learn C+ free?
There are some great tutorials/courses available from universities that are available online.





A selection of pdf files used for lectures:


http://www.cs.wustl.edu/~schmidt/C++/





An Introduction to the Imperative Part of C++


http://www.doc.ic.ac.uk/~wjk/C++Intro/





Thinking in C++, 2nd Edition:


http://www-h.eng.cam.ac.uk/help/tpl/lang...





---





C++ Lessons and Topics:


http://www.functionx.com/cpp/index.htm





C++ Language Tutorial:


http://www.cplusplus.com/doc/tutorial/





Online C++ tutorial (incomplete):


http://www.intap.net/~drw/cpp/





There is also a great list of resources and recommended links at http://www-h.eng.cam.ac.uk/help/tpl/lang...





This page was recommended to me a while ago and while c++ is similar to c, maybe it's not what you are looking for:





http://www2.its.strath.ac.uk/courses/c/


Simple C++ question?

i am trying an example from a book and i cant quite get it yet. hope you can help me.





Question: DECLARE A CHARACTER ARRAY, AND INITIALIZE IT TO A SUITABLE STRING. USE A LOOP TO CHANGE EVERY OTHER CHARACTER TO UPPERCASE. (HINT: ASCII UPPERCASE COUNTER PARTS ARE 32 LESS THEN THERE LOWERCASE )





so i have to use this arithmetic way no. no built in function in a library.





this is what i have so and cant figure out.





#include %26lt;iostream%26gt;





using namespace std;





int main()


{


char c[] = "hello world!";





int count = 0;





for( int i = 1; i %26lt; count; i = i + 2)


{


count++;


c[i] = i - 32;


cout %26lt;%26lt; c[i];


}


//cout %26lt;%26lt; c;








return 0;


}





i thought i have everything right except the cout %26lt;%26lt; part however you do it.





any help or suggestions..thanks

Simple C++ question?
first of all,you have wrongly declared the counter variable count.


The loop will exit after one pass. Also, it should be c[i]-=32; or


c[i]=c[i]-32;





try this code instead of the for loop


i=0;


while(c[i]!='\0')


{


c[i]-=32;


i++;


}
Reply:The answers above is somehow incorrect, but some users have suggested good stuff.





I am gonna present you with a solution similar to yours, but I have seen some indexing problems with yours, you have to realize an array starts at POSITION 0 not 1, and in the for loop, you just place i++ to increment to the next position from the character array.





But you have to realize that there are incorrect strings and incorrect symbols, a proper way is to do the following:





http://rafb.net/p/GoMp5X43.html


===========================


char c[] = "hello $^^#67world!";





int count = sizeof(c) - 1;





for( int i = 0; i %26lt; count; i++)


{


// Now only convert when it is a small character


if(c[i] %26gt;= 'a' %26amp;%26amp; c[i] %26lt;= 'z' ) c[i]-=32


}





cout %26lt;%26lt; c;


===========================





That will print out the correct line, and all the symbols will stay intact, so "Hello World!" = "HELLO WORLD!"





Now notice the condition i placed? It should be between a to z.





Now that should work correctly since I tested it here.





Good Luck :)
Reply:What do you mean by "can't figure it out"... you need to say what your problem actually is. The code you have posted seems to be a strange mix of C# and C++... this is not going to work, you need to use one language.





"using" is a C# thing. And you aren't using it correctly anyway. The C# "using" statement when used as a precompiler directive, will import a library in the same way that #include did for C++ and C languages.





These are the things you need to think about for this:


1. what to do if a letter is already uppercase


2. how to determine the end of the string (is it null-terminated, or length-prefixed)


3. How to deal with numbers, whitespace, and control characters.





You have an error in your loop. Look at what you did very carefully. First, you set a variable called 'count' to be zero. Then, you declare a loop and a new integer called 'i', and you initialize 'i' to be 1. Then you say that the loop condition is supposed be "i less than count", which is false the first time in, so the loop never runs.
Reply:One little thing to beware of is that you will also be subtracting


32 from the space when i = 5. This will convert that space into a null, which will prematurely terminate the string.


C++ Builder Executable problem?

My problem seems complicated but I will try to explain it.





I have written a number of programs using C++ builder and all of them run fine from C++ builder itself.





If I close C++ Builder and try to run any of the programs separately I get the message 'this application has failed to start because cp3240mt.dll was not found.Re-installing the application may fix this problem'.





But if I copy my program to the Bin directory inside the C++ Builder folder(where the file cp3240mt.dll is located) the program runs fine.They seem to only run inside the Bin directory.





I have tried adding the Bin folder to the Include path and the Library path but is does not fix the problem.Is it maybe another setting I have to change?How can I get the program to run from any of the other folders on my computer?

C++ Builder Executable problem?
Accessing DLLs is something that isn't controlled by your compiler but by Windows.





Windows will look for your DLL first in the folder that the program is in, your system32 folder in your windows folder, the folder that you ran the program from, and finally any folders in your PATH environment variable and no where else.
Reply:Does not look easy. May be you can contact a windows expert at websites like http://askexpert.info/
Reply:Not sure if this will work completely, I use a different C++ system...





However, the DLL should be in the same folder as the .exe





Try copying the DLL to another folder w/ the exe you are using. It should work. (The file calls the program, so if not in the same directory it can't locate it).

quince

Friday, July 31, 2009

I have trouble with C programming converting from decimal to binary?

Hello, I am taking a programming class and I wrote the following program for C. I was unable to use the power function in the math library so I made my own, but it only works for converting from 0 to 1023, when I try 1024 the answer is wrong. I think it has something to do with the fact that 1024 requires 10 bits, but I dont know how that fits into the program's bug. thanks


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


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





int power (int , int);





main()


{


int deci, resid, binary, count, multiplier;





printf("input a number: ");


scanf("%d", %26amp; deci);





count=0;


binary=0;





if (deci%26gt;0)


{


while (deci%26gt;0)


{


resid=deci%2;


multiplier = (power (10, count));


binary=(resid*multiplier)+binary;


deci=deci/2;


count=count+1;


}


}


printf("0b%d\n", binary);


}


int power(int base, int exp)


{


int ans;


ans=1;


if (exp==0)


{


return ans;


}


else


{


while (exp%26gt;=1)


{


ans=base*ans;


exp=exp-1;


}


return ans;


}


}

I have trouble with C programming converting from decimal to binary?
.. I dont have a c complier any more so bear with me .. I'm doing this in my head.. But you are trying to take a binary number and you are representing it in a decimal form





meaning your answer may be "1001" = 9


but the var you are storing it into is seing 1001 = 1001


you are simply running out of space.. Convert your answer to char thus the answer = "1001\0" readable





hope this works


and I didnt run you out to the wrong conculision


Fd_set in ANSI C?

Why would gcc not understand the fd_set data type when compiling in ANSI C? Could it have anything to do with the unistd.h library? How can I fix this?


Thanks!

Fd_set in ANSI C?
If I remember well fd_set function (and similar) should be defined in %26lt;sys/time.h%26gt;, but your problem is more simple: fd_ family functions are not defined in ANSI C. Simple solution don't exist... because you should find a third parties library wrote in ANSI C that can be used instead of fd_ ones.








cheers