Probleme mit der Vergleich von Werten im Array
-
Hallo Leute!
Folgendes Problem: Möchte in dem ersten String alle Zeichen des zweiten Strings suchen und bei gefunden noch # mit der Anzahl ausgeben. Leider bin ich nicht so bewandt mit verschachtelten For-Schleifen, ich weiss aber dass mir da eine fehlt nur wo und wie?
Progi macht alles nur für ein Zeichen:
#include <stdio.h> #include <string.h> int main() { char text[TABDIM]={"a\0"}; char vorgabetext []= "joky oyz kot zkyz-yzxotm ckx jokykt yzxotm gry kxyzk vkxyut burryzgktjom gt sgt zrkx zkintoqas cokt gz yinoiqz hkqussz ot kotkx jkx tgkinyzkt akhatmkt kotk qrk otk akhkxxgyinatm bokr kxlurm\0"; char d[]="abcdefghijklmnopqrstuvwxyz\0"; char ausgabe[11550]=""; int x, l,k, i, j, zaehler=0; printf ("Vorgegebener String:\n\njoky oyz kot zkyz-yzxotm ckx jokykt yzxotm gry kxyzk vkxyut burryzgktjom gt sgt\n"); printf ("zrkx zkintoqas cokt gz yinoiqz hkqussz ot kotkx jkx tgkinyzkt akhatmkt kotk qrk\n"); printf ("otk akhkxxgyinatm bokr kxlurm\nHistogramm:\n\n"); l=strlen(vorgabetext); x=strlen(d); i = 0; k=0; for (j=0; j<=l; j++) { if (d[i]==vorgabetext[j]) { strcat (ausgabe,"#"); zaehler++; } } printf ("\n%c %d %s\n",d[0], zaehler, ausgabe); return 0; }
Bitte um rasche Hilfe
Coolbininet
-
hi,
etwaso soll es aussehen:
#include <stdio.h> #include <string.h> int main(int argc, char **argv) { int i,j, vor_len, d_len; char vorgabetext[]= "joky oyz kot zkyz-yzxotm ckx jokykt yzxotm gry kxyzk vkxyut burryzgktjom gt sgt zrkx zkintoqas cokt gz yinoiqz hkqussz ot kotkx jkx tgkinyzkt akhatmkt kotk qrk otk akhkxxgyinatm bokr kxlurm"; char d[]="abcdefghijklmnopqrstuvwxyz"; vor_len = strlen(vorgabetext); d_len = strlen(d); for( i = 0; i < d_len; i++ ) { for( j = 0; j < vor_len; j++ ) { if( vorgabetext[j] == d[i] ) printf("vorgabetext[%d] == d[%d]\n", j, i); } } printf("\n"); return 0; }
-
Hallo!
ich muss aber die einzelnen Zeichen der Arrays ausgeben.
Grüsse
-
Willst du es so ?
#include <stdio.h> #include <string.h> int main() { char vorgabetext []= "joky oyz kot zkyz-yzxotm ckx jokykt yzxotm gry kxyzk vkxyut burryzgktjom gt sgt zrkx zkintoqas cokt gz yinoiqz hkqussz ot kotkx jkx tgkinyzkt akhatmkt kotk qrk otk akhkxxgyinatm bokr kxlurm\0"; char d[]="abcdefghijklmnopqrstuvwxyz\0"; char ausgabe[11550]=""; int x, l,k, i, j, zaehler=0; printf ("Vorgegebener String:\n\njoky oyz kot zkyz-yzxotm ckx jokykt yzxotm gry kxyzk vkxyut burryzgktjom gt sgt\n"); printf ("zrkx zkintoqas cokt gz yinoiqz hkqussz ot kotkx jkx tgkinyzkt akhatmkt kotk qrk\n"); printf ("otk akhkxxgyinatm bokr kxlurm\nHistogramm:\n\n"); l=strlen(vorgabetext); x=strlen(d); i = 0; k=0; for (i=0; i < x; i++) { for (j=0; j < l; j++) { if (d[i]==vorgabetext[j]) { strcat (ausgabe,"#"); zaehler++; } } printf ("%c %5d %s\n",d[i], zaehler, ausgabe); zaehler = 0; ausgabe[0]='\0'; } return 0; }
Kurt
-
hier hast du noch ein paar deutsche wahrscheinlichkeiten:
'e': .153239, 'n': .091616, 'i': .081347, 'r': .075886, 't': .064651, 's': .063490, 'a': .061171, 'd': .047471, 'h': .042971, 'l': .042538, 'u': .037444, 'o': .032679, 'c': .030951, 'g': .030215, 'm': .027488, 'b': .023358, 'f': .018104, 'k': .016973, 'w': .015214, 'p': .013943, 'z': .011788, 'v': .009329, 'j': .003208, 'y': .002837, 'x': .001501, 'q': .000588,
im uebrigen ist es eine spezielle monoalphabetische verschluesselung, bekannt als caesarcipher.
und weil mir grad so ist, hier meine histogrammimplementation:
/* * --------------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * <christoph.rackwitz@gmail.com> wrote this file. As long as you retain this notice * you can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return -- Christoph Rackwitz * --------------------------------------------------------------------------------- */ #include <stdio.h> #include <ctype.h> int main(void) { int histo[27] = {0}, i, c; while ((c = getchar()) != EOF) { c = toupper(c) - '@'; if (c < 1 || c > 26) histo[0]++; else histo[c]++; } printf("?: %3d\n", histo[0]); c = 0; for (i = 1; i <= 26; ++i) if (c += histo[i], histo[i]) printf("%c: %3d\n", '@'+i, histo[i]); printf("Buchstaben gesamt: %d\n", c); return 0; }
-
sie können sich mit fragen zu den übungsbeispielen natürlich auch vertrauensvoll an ihre lektoren und/oder tutoren wenden
mfg
-step--
di stephan mantler | Brain, n.: apparatus with
mantler@technikum-wien.at | which we think that we think