#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <math.h>
// Here i declared global variables.
int repLetters[26];
char* letters1;
static void makeRepLetters()
{
printf("enter makeRep");
int i =0;
for(;i<26;i++)
repLetters[i] =0;
for(i=0;i<26;i++) {
repLetters[((letters1[i]) - 97)] +=1;
}
}
int main(int argc, char *argv[])
{
int i=0,num =10;
if(argc != 2) {
printf("Usage: %s <letters>\n", argv[0]);
return 1;
}
//letters1 = (char*)malloc(sizeof(char)* strlen( argv[1]));
//strcpy(letters1,argv[1]);
letters1 = argv[1];
printf("\n letters1 = %s",letters1);
scanf("%d",&num);
printf("\ncheck test\n");
makeRepLetters();
for(i=0;i<26;i++)
printf("\n %c occured %d tyms",i+97,repLetters[i]);
return 0;
}
打印“检查测试”后,出现总线错误。makeRepLetters
没有被调用。我尝试改变很多东西,但无法让它发挥作用。