Why am I getting an "Expected Identifier" error?

Why am I getting this error? Error expected declaration specifiers or before given?

  • #include <stdio.h> void copy_substring(char given_string[], int from_posn, int no_char, char new_string[]); main() { char crazy[5]; char given[] = "Anonymous"; void copy_substring(given[],0,3, crazy[]); } void copy_substring(char given_string[], int from_posn, int no_char, char new_string[]) { int i; for (i=0;i<no_char; ++i) { new_string[i] = given_string[from_posn-1+i]; } new_string[i] = '\0'; } I am getting this error : /home/Documents/code/c/substrToString.c|7|error: expected declaration specifiers or ‘...’ before ‘given’|

  • Answer:

    You need to make some changes ! #include <stdio.h> void copy_substring(char given_string[], int from_posn, int no_char, char new_string[]); main() { char crazy[5]; char given[] = "Anonymous"; // void copy_substring(given[],0,3, crazy[]); copy_substring(given, 0, 3, crazy); } void copy_substring(char given_string[], int from_posn, int no_char, char new_string[]) { int i; for (i=0;i<no_char; ++i) { // new_string[i] = given_string[from_posn-1+i]; new_string[i] = given_string[from_posn+i]; } new_string[i] = '\0'; }

Bharat Khatri at Quora Visit the source

Was this solution helpful to you?

Other answers

I guess stack overflow would have been a better place to ask this question. Quora is slightly more generalised. :)

Ritwik Dey

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.