#include <stdio.h>
#include <string>
char czestosc(char napis)
{
char napisstring[] ={"napis"};
int tab[256];
int i;
for (i=0;i<256;++i)
{
tab[i]=0;
}
for(int j=0;j<strlen(napisstring);++j)
{
tab[napisstring[j]]++;
}
for(int i=0;i<256;++i){
if(tab[i]>0) {
printf("make %d digit %d", i, tab[i]);
}
}
}
int main(){
czestosc('123114');
getchar();
system("PAUSE");
return 0;
}
Pojawiaja sie dziwne liczby a założeniem tego programu jest by z zmiennej czestosc liczył ile razy pojawi sie jaki znak. podejrzewam ze problem lezy w 2 pierwszych linijkach char czestosc(char napis)
{
char napisstring[] ={"napis"};
a sugerowałem się kodem w C++ tj.
#include <iostream>
using namespace std;
void czestosc(string napis){
int tab[256];
for(int i=0;i<256;++i)
tab[i]=0;
for(int j=0;j<napis.length();++j)
tab[napis[j]]++;
for(int i=0;i<256;++i)
if(tab[i]>0) cout<<(char)i<<" - "<<tab[i]<<endl;
}
int main(){
czestosc("016979797");
system("PAUSE");
return 0;
}
Jestem nowy w programowaniu prosze o wyrozumialosc;)