Looks like the topic was very essential to be opened.I am happy for that. I can make a statement too I think.There is a difference. Because arrays dont really act like a pointer.
Code:
#include <stdio.h>
int main(void)
{
char a[6]="naber";
a=&a[3];
printf("%s",a);
return 0;
}
This code gives error. Unlike :
Code:
#include <stdio.h>
int main(void)
{
char *a="naber";
a=&a[3];
printf("%s",a);
return 0;
}
This code however, does not give error. In my opinion , the arrays just act in resemblence with pointers. Because in order to change the adress of string (assume it is an array) we have to use it as &string[0]. I may be looking to the case simply. But I have been thinking this way. If I am wrong please clarify me. By the way , here is the code of the program which counts each different word in a sentence:
Code:
#include <stdio.h>
#include <string.h>
void sayac(char *,char *,int,int *);
int main()
{
struct str {
char d[10];
} st[8];
char s[80];
char kopya[80];
gets(s);
sprintf(kopya,"%s",s);
char *b;
b=strtok(s," ");
int x=0;
int i=0;
for(i=0;i<8;i++) {
x+=1;
sprintf(st[i].d,"%s",b);
b=strtok(NULL," ");
if(b==NULL) break; }
int y=0;
int k=0;
int control=0;
int p=0;
for(i=0;i<x;i++) {
for(k=0;k<i;k++)
if((strcmp(st[i].d,st[k].d))==0) control=1;
if(control==1) continue;
y=strlen(st[i].d);
sprintf(s,"%s",kopya);
sayac(s,&(st[i].d[0]),y,&p);
printf("%s den %d tane var\n",st[i].d,p);
p=0;
}
return 0;
}
void sayac(char *ana,char *str,int t,int *ptr) {
if(strstr(ana,str)==NULL) return;
else {
ana=strstr(ana,str);
*ptr=*ptr+1;
sayac(&ana[t],str,t,ptr); }
}
Sorry for the mess of code lines. This is the way I write.
Thank you for every response. =) By the way that post someone posted which leads us to another site , actually explains what I knew. That is true isnt that?