I can get anything to work , it just messes my code up even more, not even worth posting cause it is evidently way wrong. :(
Printable View
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.
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.
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.Quote:
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.
Hint: strlen() returns the length of a string. UsingQuote:
IS 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]
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;
}