+ 3

Calling a function withing itself. Good practice?

/* * File: main.c * Author: Danstan * * Created on March 14, 2017, 11:06 AM */ #include <stdio.h> #include <stdlib.h> void login(void) { int token = 0; int loggin=0; char x; printf("Enter some text To Login\n"); scanf("%s",&x); while (1) { //login admin if (loggin == 1 && token == 1) { printf("You are logged in\n"); break; } else if (loggin == 0 || token == 0) { printf("Please Login\n"); login(); break; } else { printf("Please Login\n"); login(); break; } } } int main(int argc, char *argv[]) { login(); exit; }

14th Mar 2017, 8:38 AM
Zemuldo
Zemuldo - avatar
1 ответ
+ 4
yes it saves time and keep the code more efficient and more light. but keep in mind not to make an infinite recursion.
14th Mar 2017, 8:40 AM
Mayank Sahai
Mayank Sahai - avatar