>Have to make C caesar encryption program
>Nutshell: every character has a value, take that value and shift it up one
>ABC encrypts to BCD
>Use an array
So far I've made this pesudo code so far:
http://pastebin.com/AbAXgnAX
What i'm stuck on is how to make a while loop without the program knowing the amount of entered characters, is there some way to make a counter for the users input while still using an array? (I think it be easier without one)
>pls go ez on me m8s, i'm an electrical engineer in baby coding classes
>>57650363
Why are you using an array? Just read from stdin and use getchar() https://en.m.wikibooks.org/wiki/C_Programming/C_Reference/stdio.h/getchar
>>57650363
Have it run through until it encounters the end of string character, I think its \0
>>57650819
we have to for the assignment
>>57650363
Also Z->A and not whatever unprintable character is after.
Encryption is for spooge ovaltine drinking fagots. I could publish my pin number. God is perfectly just. It's busywork bullshit for catle
>>57650925
Stop cosplaying as terry
>>57650925
Terry?
>>57650925
NSA shill leave my enhanced bullettin board.
>>57650925
NSA getting this triggered by basic encryption
>>57650896
I see. Use a for loop that checks if the index is less than the array size AND if the current char is different from '\0'
Allocate some initial size, say 256 characters. Keep a size_t for how big array is currently. Until done reading input, Write input into array, if you hit the end allocate a new array of twice previous size and copy all the data into it and then keep writing input
Like this?#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char in[10];
char ceasar[10];
puts("Input plz: ");
scanf("%9s", in);
for (int i = 0; i < strlen(in); ++i) {
ceasar[i] = in[i] + 3; // modulo blabla
}
ceasar[9] = 0;
printf("%s\n", ceasar);
}
>>57650363
Ok, I'm in good mood today, so I'll help you.
1. Per convention, a C-style string ends when a '\0' character is found. Keep scanning until you either find the end of the string or a '\0'. Otherwise ugly things might happen. Using a "while" loop is the right direction to take.
2. Try to avoid scanf to get string values. Use fgets instead, like this. (If you want to know what's stdin, it's basically using the console as input)char whereillstorestuff[80];
fgets(whereillstorestuff, 80, stdin);
3. Think in what happens if your character is 'z'. It doesn't turn itself into an 'a' if you increment it by one. Be careful.
>>57650925
gtfo CIA nigger
char* input = calloc(char, 1);
char input_character = 0;
while((input_character = getchar()) != '\n')
asprintf(&input, "%s%c", input, input_character);
[\code]
Something like this may work well for getting input, sorry if there are any mistakes I'm on mobile.
if I want to use parameters shall I use :
int main(int ac, char **av)
Or :
int main(int ac, char *av[])
is there any difference ??
>>57651616
no difference really, but call it argc and argv
>>57651616
None.
An array is a pointer after all. For example, doing:char thisthing[] = "Some string";
putchar(thisthing[0]);
is the same aschar thisthing[] = "Some string";
putchar(*thisthing);
Why don't you learn the basics of programming clean code before you make a soup mess of big boy programs?
Your code looks like shit, I cant imagine trying to read through it if you implemented any sort of non retard algorithm.
>>57651680
hm why is it so important ? I find quicker to just give it a shorter name, thanks.