This is my code. I am getting some weird warning's when I run it and I'm confused on why. Warnings on the bottom. My code will still run and the output is correct, however I still want to understand and fix the warnings thanks. I tried to fix all the warnings, however when I do my code won't output correctly anymore. My program fails. So I am confused. Please help!
#include <stdio.h> #include <stdlib.h> char s1(char *random); char s2(char *s2_input, int index); char strfilter(char *random, char *s2_input, char replacement); int main() { int s1_index = 41; char s1_random[s1_index]; s1(s1_random); printf("\ns1 = "); puts(s1_random); printf("s2 = "); int s2_index = 21; char s2_input[s2_index]; s2(s2_input, s2_index); if(s2_input[1] == '\0') { printf("size too small"); exit(0); } printf("ch = "); char replacement = getchar(); printf("\n"); int filter_index = 41; strfilter(s1_random, s2_input, replacement); printf("\ns1 filtered = "); puts(s1_random); } char s1(char *random) { int limit = 0; char characters; while(characters = ('A' + (rand() % 26))) /* random generatro */ { if(limit == 41) { *(random + 41 - 1) = '\0'; break; } *(random + limit) = characters; limit++; } } char s2(char *s2_input, int index) { char array[21] = "123456789012345678901"; /* populated array to make sure no random memory is made */ char input; int count = 0; int check = 0; while(input = getchar() ) { if(input == '\n') { *(s2_input + count) = '\0'; break; } else if(input < 65 || input > 90) { printf("invalid input"); exit(0); } *(s2_input + count) = input; count++; } index = count; } char strfilter(char *random, char *s2_input, char replacement) /* replacement function */ { while(*s2_input) { char *temp = random; while(*temp) { if(*temp == *s2_input) *temp = replacement; temp++; } s2_input++; } } ** Error message: **
matthew.c:41:22: warning: using the result of an assignment as a condition without parentheses [-Wparentheses] while(characters = ('A' + (rand() % 26))) /* random generatro */ ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ matthew.c:41:22: note: place parentheses around the assignment to silence this warning while(characters = ('A' + (rand() % 26))) /* random generatro */ ^ ( ) matthew.c:41:22: note: use '==' to turn this assignment into an equality comparison while(characters = ('A' + (rand() % 26))) /* random generatro */ ^ == matthew.c:51:1: warning: non-void function does not return a value [-Wreturn-type] } ^ matthew.c:61:17: warning: using the result of an assignment as a condition without parentheses [-Wparentheses] while(input = getchar() ) ~~~~~~^~~~~~~~~~~ matthew.c:61:17: note: place parentheses around the assignment to silence this warning while(input = getchar() ) ^ ( ) matthew.c:61:17: note: use '==' to turn this assignment into an equality comparison while(input = getchar() ) ^ == matthew.c:80:1: warning: non-void function does not return a value in all control paths [-Wreturn-type] } ^ matthew.c:96:1: warning: non-void function does not return a value [-Wreturn-type] } ^ 5 warnings generated. I tried what the compiler says to do, such as ==, or adding the parenthesis but then my code won't run correctly if I do that. So I am confused.