Hi,
I've some problems to get over, first of all, i keep getting this error and couldn't get it solved. here is the code and the error i get:
the error: error C2664: 'strtok' : cannot convert parameter 1 from 'const char []' to 'char *'
Second question: This piece of code is from a high school programming contest, the question is to determine the output by mind. I answered the question wrong, give it a try and please explain the output comes out you chose(by the way, don't mind the preprocessor statements, return 0, etc):Code:#include <stdio.h> #include <string.h> #include <ctype.h> void countletters(const char a[]); int main() { char string[80]; puts("Text Analysis 1.0"); puts("Please enter a string to be analyzed"); scanf("%s",string); countletters(string); return 0; } void countletters(const char a[]) { int letters[26]={0}; int length; int wordlength[11]; char *token; int i,x; length = (int)strlen(a); printf("Lenght of the text is: %d\n",length); puts("Number of occurences of each letter:"); for (i=0; i<length; ++i) { x=tolower(a[i]); x -= 97; ++letters[x]; } for (i=0;i<26;++i) { printf("%c:%d\t",97+i,letters[i]); if (!((i+2)%9)) printf("\n"); } puts("The lengths of the words in the sentence:"); token = strtok(a," "); while (token != NULL) { x=strlen(token); ++wordlength[x]; strtok(NULL, " "); } for (i=1;i<11;++i) printf("%d%s%d\n",i," letter words: ",wordlength[i]); }
a) 1 2 3 4 5Code:void f(int p[],int q[]) { int a[5]={1,2,3,4,5}; static int b[5]={-1,-2,-3,-4,-5}; p = a; q = b; } main() { int i,j, p[5]={2,4,6,8,10}, q[5]={1,3,5,7,9}; f(p,q); for(i=0;i<5;i++) p[i] += q[i]; for(i=0;i<5;i++) printf("%d ",p[i]); }
b) 2 5 8 11 14
c) 0 1 2 3 4
d) 3 7 11 15 19
e) none of the above
Thank you for your help and kind concern!



LinkBack URL
About LinkBacks


