Reputation: 579
I am trying to get the nth character of a string. I am currently using this:
char ch = Word[n];
However, when I build it, it gives me the following error:
error: subscripted value is neither array nor pointer nor vector
I am very confused about why I have this error!
My Whole code is:
#include <stdio.h>
#include <string.h>
#define alpha[] [a b c d e f g h i j k m n o p q r s t u v w x y z]
hash(Word){
char hashed;
int t, length;
length = strlen(Word);
for (t; length; ++t) {
char ch = Word[t];
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
int position alpha[ch];
ch += 9;
strncat(hashed, &ch, 1);
}
else if(ch >= '0' && ch <= '9')
{
ch*=2;
char letter alpha[ch];
strncat(hashed, &ch, 1);
}
else
{
strncat(hashed, &ch, 1);
}
printf("%s/n", hashed);
}
return hashed;
}
main(){
printf("Please enter your string to hash: ")
scanf("%s", WordToHash)
char* HashedWord
HashedWord = hash(WordToHash)
printf("/nYour hashed word is %s", HashedWord)
}
My compiler is the basic one that is pre-installed when you install code::blocks through the AUR in manjaro.
By the way, I am a newbie to C (I only started yesterday)!
Thanks in advance!
Upvotes: 0
Views: 52
Reputation: 2914
I don't know what kind of C this is, but sure doesn't look like standard C. C is strong-typed language. You have to declare the type of a variable before using it. Also, functions need to have return types. In your case, you should replace
hash(Word){
with
char* hash(char* Word){
I also see some other strange things in your code that shouldn't work/compile in C. My advice is to master the basics first and then get back to this example.
Upvotes: 1