Everytime i think i get this i mess it up.
Code:
#include<stdio.h>
#include<math.h>
typedef int boolean;
#define true 1
#define false 0
char Shift(char Achar,int Shifts)
{
boolean Shiftleft =
Shifts <= 0;
if (Shiftleft)
Shifts=sqrt(pow(Shifts,2)); //i wonder if -1*val would be faster
int Lowerbound = 33;
int Remainder;
int Upperbound = 126;
Remainder =
Shifts%(Upperbound-Lowerbound);
if (Shiftleft)
{
if (Remainder>
(int)Achar-Lowerbound)
{
return (char)(Upperbound+(((int)Achar-Lowerbound)-Remainder)+1);
}
else return (char)((int)Achar-Remainder);
}
else
{
if (Remainder>
Upperbound-(int)Achar)
{
return (char)(Lowerbound+(Remainder-(Upperbound-(int)Achar))-1);
}
else return (char)((int)Achar+Remainder);
}
}
int Encryption(char *AString,char *Buffer,int *NewLength)
{
int i = 0 ;
*NewLength = strlen(AString)+1;
Buffer = malloc(*NewLength);
printf("Func Length : %i\n",*NewLength);
for (i;i!=*NewLength;i++)
{
Buffer[i]=AString[i];
}
Buffer[i+1]='\0';
printf("In Func: %s\n",Buffer);
return 1;
}
#include<stdio.h>
#include<stdlib.h>
int Changec(char *Arr)
{
Arr[1]='G';
return 1;
}
void Changei(int *Pointer)
{
*Pointer=3;
}
int main(void)
{
int strLength;
char NewStr[0];
Encryption("a",NewStr,&strLength);
printf("Encrypted Str : %s\n",NewStr);
printf("New Length : %i\n",strLength);
return 0;
}
The encrypted string comes back as a smiley face. A very...very...friendly smiley.
Any Help?
If someone could explain how to use malloc and realloc properly that'd be nice XC