Created
April 12, 2011 08:38
-
-
Save JeGa/915186 to your computer and use it in GitHub Desktop.
Login name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//--------------------------------------------------------------------------- | |
//--------------------------------------------------------------------------- | |
#include <conio.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
char * stringToUpper(char * str) { | |
for(int i = 0; i < (int)strlen(str); i++) | |
str[i] = toupper(str[i]); | |
return str; | |
} | |
void loginName() { | |
char name[15], vorname[15], login[9]; | |
FILE * fptrIn; | |
FILE * fptrOut; | |
fptrIn = fopen("name.txt" , "r"); | |
fptrOut = fopen("login.txt" , "w"); | |
if(fptrIn == NULL) perror("Error opening file"); | |
else { | |
if(fptrOut == NULL) perror("Error opening file"); | |
else { | |
while(!feof(fptrIn)) { | |
fscanf(fptrIn, "%s", name); | |
fscanf(fptrIn, "%s", vorname); | |
if(strlen(name) >= 6) { | |
strncpy(login, stringToUpper(name), 6); | |
} else { | |
strcpy(login, stringToUpper(name)); | |
for(int i=1; i <= (int)(6 - strlen(name)); i++) { | |
strcat(login, "x"); | |
} | |
} | |
login[6] = vorname[0]; | |
login[7] = vorname[1]; | |
login[8] = '\0'; | |
fprintf(fptrOut, "%s\n", login); | |
getch(); | |
} | |
} | |
} | |
fclose(fptrIn); | |
fclose(fptrOut); | |
} | |
int main() { | |
loginName(); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment