Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need nelp with this kind of error in my 6 program to make it works: ve2.c:74:1

ID: 3861424 • Letter: I

Question

I need nelp with this kind of error in my 6 program to make it works:

ve2.c:74:1: warning: control may reach end of non-void function [-Wreturn-type]

Particulary in the 3 functions :

The code:

#include<stdio.h>

#include <stdlib.h>

char arr[26][26];

char message[22], key[22], emessage[22], retMessage[22];

int findRow(char);

int findColumn(char);

int findDecRow(char, int);

int main()

{

int i = 0, j, k, r, c;

k = 96;

for (i = 0; i<26; i++)

{

k++;

for (j = 0; j<26; j++)

{

arr[i][j] = k++;

if (k == 123)

k = 97;

}

}

printf(" Enter message ");

fgets(message, 22, stdin);

printf(" Enter the key ");

fgets(key, 22, stdin);

for (i = 0; key[i] != ''; i++) //Use '', not NULL

{

c = findRow(key[i]);

r = findColumn(message[i]);

emessage[i] = arr[r][c];

}

emessage[i] = '';

printf(" Encrypted message is: ");

for (i = 0; emessage[i] != ''; i++) //Use '', not NULL

printf("%c", emessage[i]);

//decryption

for (i = 0; key[i] != ''; i++) //Use '', not NULL

{

c = findColumn(key[i]);

r = findDecRow(emessage[i], c);

retMessage[i] = arr[r][0];

}

printf(" Message Retrieved is: ");

for (i = 0; emessage[i] != ''; i++) //Use '', not NULL

printf("%c", emessage[i]);

//decryption

for (i = 0; key[i] != ''; i++) //Use '', not NULL

{

c = findColumn(key[i]);

r = findDecRow(emessage[i], c);

retMessage[i] = arr[r][0];

}

retMessage[i] = '';

printf(" Message Retrieved is: ");

for (i = 0; retMessage[i+1] != ''; i++)

printf("%c", retMessage[i]);

getchar();

return(0);

}

int findRow(char c)

{

int i;

for (i = 0; i<26; i++)

{

if (arr[0][i] == c)

return (i);

}

}

int findColumn(char c)

{

int i;

for (i = 0; i<26; i++)

{

if (arr[i][0] == c)

return (i);

}

}

int findDecRow(char c, int j)

{

int i;

for (i = 0; i<26; i++)

{

if (arr[i][j] == c)

return (i);

}

}

output should be:

ve2.c:74:1: warning control may reach end of non-void function [-Wreturn-type] ve2.c:84:1: warning control may reach end of non-void function [-Wreturn-type] ve2.c:93:1: warning control may reach end of non-void function [-Wreturn-type] 3 warnings generated.

Explanation / Answer

This error is occuring because return(i); is mentioned with in if statement. There is a posibility of not going into if statement if condition is wrong. Hence compiler is warning that there is a posibility of not returning any thing.

Return some other value out side loop, as you are writing for main() function return(0);.

So that worng will be removed.