update
This commit is contained in:
@@ -15,11 +15,14 @@ int main() {
|
||||
|
||||
printf("\nEingabe: %s", eingabe);
|
||||
|
||||
for (index = 0; eingabe[index] != '\0'; index++)
|
||||
if (eingabe[index] == 'a')
|
||||
for (index = 0; eingabe[index] != '\0'; index++)
|
||||
if (eingabe[index] == 'a')
|
||||
break;
|
||||
|
||||
if (eingabe[index] == '\0')
|
||||
printf("Der String enthält kein ’a’.");
|
||||
else
|
||||
printf("Das erste 'a' ist an Position %d.\n", index + 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,17 +10,18 @@ int main() {
|
||||
|
||||
int num1, num2;
|
||||
num1 = 0;
|
||||
nun2 = 1;
|
||||
num2 = 1;
|
||||
|
||||
printf("Der Quotient der Variablen ist: ")
|
||||
printf("Der Quotient der Variablen ist: ");
|
||||
printf("%d\n", num1/num2);
|
||||
printf(\n); // Leerzeile
|
||||
printf("\n"); // Leerzeile
|
||||
|
||||
printf("Jetzt werden die Variablenwerte vertauscht.\n");
|
||||
|
||||
// Dies muss korrigiert werden. (logischer Fehler!!!)
|
||||
int temp = num1;
|
||||
num1 = num2;
|
||||
num2 = num1;
|
||||
num2 = temp;
|
||||
|
||||
printf("Der Quotient der Vaiablen ist nun: ");
|
||||
printf("%d\n", num1/num2);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
char statS[] = "Hallo, PdP!";
|
||||
|
||||
char *dynS = malloc( 50 * sizeof(char));
|
||||
if (dynS == NULL){
|
||||
printf("Speicher konnte nicht reserviert werden");
|
||||
return 1;
|
||||
}
|
||||
strcpy(dynS, "Hallo, PdP!");
|
||||
|
||||
printf("%s\n", statS);
|
||||
printf("%s\n", dynS);
|
||||
|
||||
statS[1] = 'e';
|
||||
dynS[1] = 'e';
|
||||
printf("%s\n", statS);
|
||||
printf("%s\n", dynS);
|
||||
|
||||
strcpy(statS, "neuer String");
|
||||
strcpy(dynS, "neuer String");
|
||||
|
||||
printf("%s\n", statS);
|
||||
printf("%s\n", dynS);
|
||||
|
||||
free(dynS);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX 40
|
||||
|
||||
int main(){
|
||||
|
||||
char s1 [MAX];
|
||||
char s2 [MAX];
|
||||
|
||||
printf("Bitte Vorname eingeben (max. %d Zeichen): ", MAX-1);
|
||||
fgets(s1, MAX, stdin);
|
||||
|
||||
size_t len = strlen(s1);
|
||||
if (len > 0 && s1[len - 1] == '\n') {
|
||||
s1[len - 1] = '\0';
|
||||
}
|
||||
|
||||
printf("Bitte Nachname eingeben (max. %d Zeichen): ", MAX-1);
|
||||
fgets(s2, MAX, stdin);
|
||||
|
||||
len = strlen(s2);
|
||||
if (len > 0 && s2[len - 1] == '\n') {
|
||||
s2[len - 1] = '\0';
|
||||
}
|
||||
|
||||
if (strcmp(s1, s2) == 0) {
|
||||
printf("Vorname und Nachname sind gleich.\n");
|
||||
} else {
|
||||
printf("Vorname und Nachname sind nicht gleich.\n");
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
while(s2[index] != '\0'){
|
||||
if (s2[index] >= 'a' && s2[index] <= 'z'){
|
||||
s2[index] -= 'a'-'A';
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
printf("Einzeln: %s %s \n", s1,s2);
|
||||
|
||||
|
||||
char *name = malloc( 80 * sizeof(char));
|
||||
if (name==NULL){
|
||||
printf("Konnte nicht reserviert werden");
|
||||
return 1;
|
||||
}
|
||||
|
||||
strcpy(name, s1);
|
||||
strcat(name, " ");
|
||||
strcat(name, s2);
|
||||
|
||||
|
||||
printf("Zusammen: %s \n", name);
|
||||
printf("Laenge name: %zu\n", strlen(name));
|
||||
|
||||
free(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user