Strings and Characters in arrays.

This is a discussion on Strings and Characters in arrays. within the C Programming forums, part of the General Programming Boards category; Write a function to convert a letter to a number. Write a function to convert a number to a letter. ...

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Write a function to convert a letter to a number.
    Write a function to convert a number to a letter.
    Run your input through your function of choice.


    Quzah.
    Hope is the first step on the road to disappointment.

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    36
    ok
    just while im in the middle of trying stuff then....
    I noticed that when I have

    temp = pow(array1[i],3);

    it calculates the right number,

    but if I have

    temp = pow(array1[i],7);

    it doesnt calculate the number to the power of 7 correctly. Does the pow() function not allow past a certain number?
    Is there anyway I could make this work....

  3. #18
    Registered User
    Join Date
    Apr 2006
    Posts
    36
    ok wait i have to use something larger than an int dont i?

  4. #19
    Registered User
    Join Date
    Apr 2006
    Posts
    36

    ahhhhh!

    ok i donno

    Code:
    int i;
    double temp2;
    double cseven[30];
    
                             printf("\n Decryption: \t");
    		for (i=0; i<length; i++) {
    	                temp2 =  pow(array1[i],7);
    	                cseven[i] = temp2%33;
    	                printf(" %f  ", cseven[i]);
    }

    when I try longints, it doesnt work, when I try floats or doubles I know it works because if I print out temp2 afterwords it is correct. But if I then do: cseven[i] = temp2%33; etc... as above when compiling I get the error:

    illegal use of floating point in function
    temp2 is assigned a value that is never used...

    please help

  5. #20
    Registered User
    Join Date
    Apr 2006
    Location
    Plymouth, U.K.
    Posts
    13
    Perhaps you should convert the double into an int and then do it Not sure it'll work but it's just an idea.

  6. #21
    Registered User
    Join Date
    Apr 2006
    Posts
    36
    nope now im gettin the wrong answer again

  7. #22
    Registered User
    Join Date
    Apr 2006
    Posts
    36

    Angry

    It seems you cant modulus a float or double,
    and when i do this....

    Code:
    int i;
    	double temp2;
    	int cseven[30];
    	long temp3;
    
    
    		  printf("\n Decryption: \n");
    	                        for (i=0; i<length; i++) {
    			  temp2 = pow(array1[i],7);
    			temp3 = temp2;
    			printf(" %ld \n ", temp3);
                                                     printf(" %ld \n ", temp3%33);
    			 }
    It seems to only work to an extent, if array1[i] is like over a certain number, it won't work. It works if array1[i] is 21, but not 26.
    so stuck.....

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    26^7 is what number? Big. Too big in fact to fit in a 32 bit number. You can't hold infinity in 32 bits.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #24
    Registered User
    Join Date
    Apr 2006
    Posts
    36
    Yea i figured size was the problem, The answer for 26^7 is 8031810176. I just wanted to know was there a way to get around it.

  10. #25
    Registered User
    Join Date
    Apr 2006
    Posts
    36

    yay

    ok figured out how to get the right answer,

    after using alot of temps!

    Code:
    printf("\n Decryption: \n");
    			   for (i=0; i<length; i++) {
    			  temp2 = (double)pow(ciphertext[i],7);
    				temp3 = temp2/33;
    				temp5 = temp3;
    				temp6 = temp5;
    				temp4 = temp6*33;
    				printf(" temp 5 is %ld \n\n ", temp5);
    				printf(" temp 4 is %f \n ", temp4);
    				temp7 = temp2-temp4;
    				cseven[i] = temp7;
    				printf(" temp 7 is %d \n ", cseven[i]);
    			 }
    It prints the correct answers as would using %. Thanks for all help given.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Removing Specific Characters from Strings
    By gfmartin05 in forum C++ Programming
    Replies: 4
    Last Post: 02-09-2009, 08:53 AM
  2. Strings and Substrings using arrays
    By dcwang3 in forum C Programming
    Replies: 12
    Last Post: 02-18-2008, 06:28 AM
  3. Problems with Strings and Arrays.
    By SlyMaelstrom in forum C++ Programming
    Replies: 13
    Last Post: 04-15-2005, 02:13 PM
  4. strings or arrays of characters?
    By Callith in forum C++ Programming
    Replies: 13
    Last Post: 12-26-2004, 10:28 AM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21