Add a Makefile so that typing make compiles the program, reverse.c into the executable reverse.exec, and typing make test runs 3 tests. Typing make clean should remove any generated files.
Add a Makefile so that typing make compiles the
typing make test runs 3 tests. Typing make clean should remove any generated files.
Program for reverse.c:
#include <stdio.h>
char * make_reverse(char * word){
int i, len=0;
char temp;
while(word[len]){
len++;
}
for(i=0; i<len/2; ++i){
temp = word[i];
word[i]=word[len-i-1];
word[len-i-1]=temp;
}
return word;
}
int main(){
char str[]="James";
printf("%s", reverse(str));
return 0;
}
Logically it’s seems impossible to write a C program without using a main() function. Since every program must have a main() function because:-
- It’s an entry point of every C/C++ program.
- All Predefined and User-defined Functions are called directly or indirectly through the main.
Therefore we will use preprocessor(a program which processes the source code before compilation) directive #define with arguments to give an impression that the program runs without main. But in reality it runs with a hidden main function.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps