hi, i'm trying to figure out how to fix this warning:
decode.c(77) : warning C4715: 'get_msg' : not all control paths return a value
i understand that my get_msg could not always return a value, i'm just not sure how to state that in my code? can anyone suggest anything? should i use an if/else statement?

#include <stdio.h>

 

#define MAX 53

FILE *csis, *fp;

void get_code(char code[]);

int get_msg(int msg[]);

void sort_msg(int msg[],int msg_size);

void decode_msg(char code[], int msg[], int msd_size);

 

void main(void)

{ //Start

    char code[MAX];

    int msg[MAX];

    int msg_size;


 

      get_code(code);

    msg_size = get_msg(msg);

    sort_msg(msg, msg_size);

    decode_msg(code, msg, msg_size);

}//End main

void get_code(char code[])
{
	int i;
	
	fopen_s(&fp, "codefile.txt", "r");  


		while (!feof(fp)) //loops file till end

            fscanf_s(fp, "%c\n", &code); //places file contents in i
		
        for (i = 0; code[i]= *code; i++) //adds i to it self to continue with contents

    

;}//end get_code

 

int get_msg(int msg[]){

	int j;

 
     fopen_s(&csis, "msgfile.txt", "r");


        while (!feof(csis))

            fscanf_s(csis, "%c\n", &msg);

        for (j = 0; msg[j]= *msg; j++)
		
		return j;

}//end get_msg

 

void sort_msg(int msg[],int msg_size){

	int i, j, temp;

     for (i = 1; i < msg_size; i++) {

          temp = msg[i];

          j = i - 1;

          while (j >= 0 && temp < msg[j]) {

              msg[j+1] = msg[j];

              j = j - 1;

          }

          msg[j+1] = temp;

     }

}//end sort_msg

void decode_msg(char code[], int msg[], int msg_size){

	int i;

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

printf("%c", code[msg[i] %10]);

       printf("\n");

}//end decode_msg

Recommended Answers

All 4 Replies

You cannot assume the for loop will be entered. By adding some default return condition at the end of your function will ensure something is returned. You also need to make sure your code is doing what you intend. If you have a for loop I assume you do indeed want to loop, but the return statement is going to exit your function...

Hopefully that helps you a little.

Cool! I have never seen a man who is ready to use ATM which sometimes pays out money but sometimes plays music only...

huh? me?

huh? me?

Nope. It's about jhuyenh's explanations, of course ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.