[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>Have to make C caesar encryption program >Nutshell: e

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 20
Thread images: 3

File: 1461465612466.jpg (3MB, 3500x2495px) Image search: [Google]
1461465612466.jpg
3MB, 3500x2495px
>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.
>>
File: 1479924984307.jpg (98KB, 800x1098px) Image search: [Google]
1479924984307.jpg
98KB, 800x1098px
>>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 as

char thisthing[] = "Some string";
putchar(*thisthing);
>>
File: 1456998284807.jpg (23KB, 504x350px) Image search: [Google]
1456998284807.jpg
23KB, 504x350px
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.
Thread posts: 20
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.