1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <cstdio>
using namespace std;
void drehen(char*);
void drehen2(char*);
int main()
{
char eingabe[20];
char drehe;
cout<<"Vertauschen"<<endl;
cout<<"==========="<<endl;
cout<<"Bitte Filenamen eingeben: ";
cin>>eingabe;
fflush(stdin);
FILE *fp=fopen("dienamen.txt", "r");
if(fp==NULL)
{
cout<<"File existiert nicht!";
return 1;
}
char zeichen[50];
while(!feof(fp))
{
//Zeile Einlesen
fgets(zeichen, 50, fp);
cout<<zeichen;
cout<<"Drehen?\t\t <J/N>: ";
cin>>drehe;
fflush(stdin);
//Drehen oder nicht
if(drehe == 'j' || drehe == 'J')
{
//drehen(zeichen);
drehen2(zeichen);
}
}
}
void drehen(char * zeile)
{
char vorname[30]="\0";
char nachname[30]="\0";
int i=0, j=0;
while(zeile[i]!= ' ')
{
nachname[i]=zeile[i];
i++;
}
i++;
while(isalnum(zeile[i]) || zeile[i]=='-')
{
vorname[j]=zeile[i];
j++;
i++;
}
strcpy(zeile, vorname);
strcat(zeile, " ");
strcat(zeile, nachname);
strcat(zeile, "\n");
cout<<"Funktion drehen1"<<endl;
cout<<zeile<<endl;
}
void drehen2 (char * zeile)
{
char vorname[30]="\0";
char nachname[30]="\0";
for(int a = 0; a<strlen(zeile); a++)
{
char b;
b=zeile[a];
if(b== ' ')
{
strncpy(vorname, zeile, a);
strcat(vorname, "\0");
int c = 0;
a++;
while(a <= strlen(zeile))
{
nachname[c]=zeile[a];
a++;
c++;
}
strcpy(zeile, nachname);
strcat(zeile, " ");
strcat(zeile, vorname);
strcat(zeile, "\n");
cout<<"Funktion drehen2"<<endl;
cout<<zeile<<endl;
}
}
}
|