I can get anything to work , it just messes my code up even more, not even worth posting cause it is evidently way wrong.
I can get anything to work , it just messes my code up even more, not even worth posting cause it is evidently way wrong.
Start simple. Make a program that reads an entire line. Compare that line with your phrase to stop looking on.Code:char buf[BUFSIZ] = {0}; FILE *fp; fp = fopen( "yourfilename", "r" ); if( fp == NULL ) ...exit the program or whatever... while( fgets( buf, BUFSIZ, fp ) != NULL ) { if( strstr( buf, "searchforthisphraseinbuf" ) == 0 ) ...break from the loop to stop reading the file... }
Quzah.
Hope is the first step on the road to disappointment.
hmm,
would something like this get me anywhere?
Code:for( x = 0; buf[ x ] != '\0'; x++ ) { if ((buf[x]>='A') && (buf[x]<='Z')) { something = 'A' + ((buf[x]-'A')+( something?? + x))%26; } }
just to get me started.
Last edited by stormfront; 11-22-2005 at 01:16 AM.
ok, im not getting anywhere with this so im concentrating on getting the alphabet to wrap around and letting the user choose the number to encode by.
I have it where the user can choose the number and it works, but it places funny characters at the end of my words. I started trying to get the alphabet to wrap around but im getting erros can someone tell me whats wrong.
thats my encode function where i let the user choose the encode value, and it is also where im trying to wrap the alphabet around.Code:void encode ( void ) { char buff[BUFSIZ]; int i = 0; int shift_value; printf( "Doing encrypt\n" ); printf("\nPlease enter the text you wish to encrypt: "); fgets(buff, sizeof(buff), stdin); if ("%s" > 'Z') { "%s" -= 'Z' - 'A'; } printf("\nEnter your encryption shift value (anything from +-1 to 25): "); scanf ("%i", &shift_value); { while ( buff[i] != '\0' ) { buff[i] = buff[i] + shift_value; i++; } } printf("\n Your encrypted text is: %s \n", buff); }
OMG that was so easy, ok, i figured this part out.Originally Posted by quzah
IS there an easy way like that that i can move the first letter of the stuff to be encoded to the end? The things people have been posting are confusing the heck out of me.
Last edited by stormfront; 11-22-2005 at 01:10 AM.
Hint: strlen() returns the length of a string. UsingIS there an easy way like that that i can move the first letter of the stuff to be encoded to the end?
will access the last character in the string.Code:buffer[strlen(buffer)-1]
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Here is something else to look at, although looking at it again after being a way a while it does look rather hideous.
Code:char *bar(char *text) { static const char alpha[][26] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", }; char *start = text; int n, k = 3; for ( ; *text; ++text ) { if ( isalpha(*text) ) { int set = islower(*text) ? 1 : 0; n = strchr(alpha[set], *text) - alpha[set] + k++; if ( n >= sizeof alpha[0] ) { *text = alpha[!set][n % sizeof alpha[0]]; } else { *text = alpha[set][n]; } } } return start; }
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*