Jump to content

Occurrence of symbols

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
zhenya

zhenya

    Newbie

  • Members
  • PipPip
  • 13 posts
What at me it is not correct with occurrence of symbols?
struct my{

char fio[40];

int numer;

char date1[40];

char date2[40];

int mark1;

int mark2;

};


int n,j; 

struct my list1[10]= { {"Vasya",433},{"zhenya",34},{"bobr",45},{"sasha",342},{"belka",4322},{"sachek",3244},{"bredly",324},{"alex",244},{"kostya",3422},{"knedlik",90}};

struct my list2[10]={ {"masha",433},{"tanya",34},{"ulya",45},{"katya",342},{"polina",4322},{"vika",3244},{"sveta",232},{"olga",23211},{"margarita",434}};

void enter(struct my *p)

{

	int a;

printf(" skol`ko?!\n");

scanf("%i",&n);

for(a=0;a<n;a++)

{

	printf(" the first list\n");

	printf("enter the date:\n");

	scanf("%s",&p[a].date1);

	printf("enter the mark:\n");

	scanf("%i",&p[a].mark1);

	printf("\n");

	printf("vvedite list2:\n");

	printf("enter the date:\n");

	scanf("%s",&p[a].date2);

	printf("enter the mark:\n");

	scanf("%i",&p[a].mark2);

}

printf("SPISOK 1:\n");

printf("# fio        nmber      date         mark\n");

printf("___________________________________________________\n");

for(a=0;a<n;a++){

		printf("%i %6s %8i %10s %12i",a,list1[a].fio,list1[a].numer,p[a].date1,p[a].mark1);

		printf("\n");}

	printf("\nSPISOK 2:\n");

printf("# fio        nmber      date         mark\n");

printf("___________________________________________________\n");

	for(a=0;a<n;a++){

printf("%i %6s  %8i %10s %12i\n",a,list2[a].fio,list2[a].numer,p[a].date2,p[a].mark2);


	}	

	//[SIZE="6"]Occurrence of symbols[/SIZE]:


	for(a=0;a<n;a++){

char arr[256];

	int i;

	for(i=0;i<256;i++)

		arr[i]=0;

		arr[list1[a].mark1]++;

	for(i=0;i<256;i++)

		if(arr[i]) printf("\n symbol %c vstrech %d raza",i,arr[i]); 

			} 


}

void main(){

	struct my *p;

	p=(struct my *)malloc(30*sizeof(my));

	if(p==NULL) exit(1);

	enter(p);	

	getch();

	free(p);
}

#2
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
Whats the given task? To print the occurance in each name or in general? You can send me private message in russian if you want. Here write in english and write the "text for user" in print functions also in english - otherwise people will not even try to understand whats going on in the code.
I guess that the task is to print the number of times each character appears in list1 in general and not in each name of list1. If thats the case, then the error is that you reset the character counting array after each name in list1.