Here is the list of the most common C errors we have seen students experience in Mimir Classroom. The list of errors will continue to grow as we learn from students’ work and as we hear from instructors like you send recommendations.
control reaches end of non-void function [-Werror=return-type]
This typically indicates that one of your functions was declared to have a return type (non-void function) but it is not returning a value. Check that every non-void function returns the expected value.
ld returned 1 exit status
This typically means that you have variables not defined and the most common cause are typos and spelling mistakes. Check for spelling differences.
stray ‘342’ in program
This means that one of your double quotation marks are invalid Unicode characters. C and C++ don’t allow «smart» quotes (i.e. ” vs «). This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks using your keyboard.
expected ‘;’ before ‘}’ token
This is typically a syntax error. Make sure that for every opening parentheses or bracket there is a matching closing one and that every statement ends with a semi-colon.
You can read more about semi-colons and statements here: http://www.cplusplus.com/doc/tutorial/control/
subscripted value is neither array nor pointer nor vector
This error refers to your use of the subscript operator to access values in an array, pointer of vector. For example, you’ve declared a single-dimensional array but you’re trying access it as a two-dimensional:
int newArray[4];
newArray[4][4] = …;
no input files
This means the file that the compiler is trying to compile doesn’t exist. Make sure the file you’re calling exists in the directory you’re in and that the extensions are either «.c» or «.h».
expected declaration or statement at end of input
This is typically a syntax error. Make sure that for every opening parentheses or bracket there is a matching closing one and that every statement ends with a semi-colon.
You can read more about semi-colons and statements here: http://www.cplusplus.com/doc/tutorial/control/
suggest parentheses around ‘&&’ within ‘||’ [-Werror=parentheses]
This error is an indication that your if-else conditional statements are missing parentheses. You can read more about if-else statement syntax here: http://www.cplusplus.com/doc/tutorial/control/
unknown type name ‘bool’
Some older versions of C don’t allow ‘bool’ as variable types. If you believe your version of C allows it, make sure you’re importing the correct libraries. You can read more about using boolean variables in C here: https://en.cppreference.com/w/c/types/boolean
statement with no effect [-Werror=unused-value]
This can happen due to a multitude of reasons, the most common stems from missing characters that make the statement invalid, i.e., you may have a line of code that doesn’t do anything due to a missing character, operator, or parentheses. For example:
int x = 0;
int y = 2;
x == y;
The last line is comparing two variables but the result of the comparison (true or false) is not being used.
expected identifier or ‘(’ before ‘}’ token
This typically means that the placement of your parentheses and curly brackets is incorrect. Make sure you’re using the correct syntax, that your statements end with a semi-colon, and that for every opening parentheses and curly bracket has a closing one.
Read more about C syntax here: http://www.cplusplus.com/doc/tutorial/control/
too many arguments for format [-Werror=format-extra-args]
Typically this refers to the amount and type of arguments passed into a function do not match the expected amount and types in the function declaration.
You can read more about function arguments and syntax here: http://www.cplusplus.com/doc/tutorial/functions/
stray ‘\222’ in program
This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks or white spaces using your keyboard.
stray ‘\210’ in program
This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks or white spaces using your keyboard.
XChr 0 / 0 / 1 Регистрация: 13.11.2013 Сообщений: 84 |
||||||||
1 |
||||||||
14.05.2015, 05:16. Показов 19577. Ответов 9 Метки нет (Все метки)
Есть 2 массива:
При попытке присвоить значение
Выскакивает ошибка:subscripted value is neither array nor pointer nor vector. Как исправить?
__________________
0 |
6044 / 2159 / 753 Регистрация: 10.12.2010 Сообщений: 6,007 Записей в блоге: 3 |
|
14.05.2015, 08:25 |
2 |
Переменная а как объявлена?
0 |
XChr 0 / 0 / 1 Регистрация: 13.11.2013 Сообщений: 84 |
||||
14.05.2015, 10:06 [ТС] |
3 |
|||
Как
0 |
HighPredator 6044 / 2159 / 753 Регистрация: 10.12.2010 Сообщений: 6,007 Записей в блоге: 3 |
||||
14.05.2015, 10:30 |
4 |
|||
XChr, в смысле
?
0 |
XChr 0 / 0 / 1 Регистрация: 13.11.2013 Сообщений: 84 |
||||
14.05.2015, 10:35 [ТС] |
5 |
|||
Да, так. Т.е. всё вместе выглядит вот так:
И при попытке присвоения какого-либо элемента tmp3[i][0] к a[i][0] выходит сообщение об ошибке
0 |
6044 / 2159 / 753 Регистрация: 10.12.2010 Сообщений: 6,007 Записей в блоге: 3 |
|
14.05.2015, 11:29 |
6 |
У меня приведенный вами код компилится и отрабатывает нормально (если убрать строку 9). Добавлено через 28 секунд
0 |
XChr 0 / 0 / 1 Регистрация: 13.11.2013 Сообщений: 84 |
||||||||
14.05.2015, 11:54 [ТС] |
7 |
|||||||
Значит, дело в стройке
, которая находится в цикле
Я просто даже не подозревал, что дело в ней, и поэтому не стал копировать в код
0 |
6044 / 2159 / 753 Регистрация: 10.12.2010 Сообщений: 6,007 Записей в блоге: 3 |
|
14.05.2015, 12:02 |
8 |
И кто у нас tmp?
0 |
XChr 0 / 0 / 1 Регистрация: 13.11.2013 Сообщений: 84 |
||||
14.05.2015, 13:59 [ТС] |
9 |
|||
Вот где оказывается ошибка была, спасибо) Но теперь программа вылетает при попытке печати
0 |
DrOffset 16631 / 8989 / 2205 Регистрация: 30.01.2014 Сообщений: 15,611 |
||||
14.05.2015, 14:51 |
10 |
|||
XChr, цикл в 113 строке. Скобки нужны ему. Следующая за циклом операция выполняется в теле цикла, а вот printf уже вне его.
1 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
14.05.2015, 14:51 |
10 |
I am writing a algorithm to solve Sudoku puzzles but my code is producing a number of errors and i cant seem to find what is going on
The errors the code returns is
error: subscripted value is neither array nor pointer nor vector
69 | row, col = find_empty_box(grid[9][9], grid, guess, row, col);
warning: passing argument 2 of ‘find_empty_box’ makes pointer from integer without a cast [-Wint-conversion]
69 | row, col = find_empty_box(grid[9][9], grid, guess, row, col);
note: expected ‘int *’ but argument is of type ‘int’
6 | bool find_empty_box(int grid[9][9], int *row, int *col)
warning: passing argument 3 of ‘find_empty_box’ makes pointer from integer without a cast [-Wint-conversion]
69 | row, col = find_empty_box(grid[9][9], grid, guess, row, col);
note: expected ‘int *’ but argument is of type ‘int’
6 | bool find_empty_box(int grid[9][9], int *row, int *col)
note: expected ‘int *’ but argument is of type ‘int’
6 | bool find_empty_box(int grid[9][9], int *row, int *col)
note: declared here
6 | bool find_empty_box(int grid[9][9], int *row, int *col)
The code is
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool find_empty_box(int grid[9][9], int *row, int *col)
{
for (int x = 0; x <= 9; ++x)
{
for (int y = 0; y < 9; ++y)
{
if (grid[x][y] == 0)
{
*row = x;
*col = y;
return true;
}
}
}
return false;
}
int Answer_Valid(int grid, int guess, int row, int col)
{
int row_values = grid[&row];
for (int i = 0; i < grid[&row]; ++i)
{
if (guess == grid[&row[&i]])
{
return false;
}
}
int column_values = grid[&col];
for (int t = 0; t <= 9; ++t)
{
for (int n = 0; n < grid[&col]; ++n)
{
if (&guess == &grid[&col[&n]])
{
return false;
}
}
}
int row_start = (row / 3) * 3;
int col_start = (col / 3) * 3;
for (int x = 0; x <= row_start && row_start + 3; ++x)
{
for (int y = 0; y < col_start && col_start + 3; ++y)
{
if (grid[&x][&y] == guess)
{
return false;
}
return true;
}
}
}
int Solver(int grid, int guess, int row, int col)
{
row, col = find_empty_box(grid[9][9], grid, guess, row, col);
if (&row == false)
{
return true;
}
for (int i = 0; (i < 1)||(i < 2)||(i < 3)||(i < 4)||(i < 5)||(i < 6)||(i < 7)||(i < 8)||(i < 9); ++i)
{
if(Answer_Valid(grid, guess, row, col))
{
grid[&row][&col] = guess;
if(Solver(grid, guess, row, col))
{
return true;
}
return false;
}
}
int LineNum = 9;
int RowAmount = 9;
for (int i = 0; i < LineNum; ++i)
{
for (int t = 0; t < RowAmount; ++t)
{
printf("%d ", grid[&i][&t]);
}
printf("n");
}
}
int main()
{
int grid[9][9] =
{
{8,0,0,0,0,0,0,0,0},
{0,0,3,6,0,0,0,0,0},
{0,7,0,0,9,0,2,0,0},
{0,5,0,0,0,7,0,0,0},
{0,0,0,0,4,5,7,0,0},
{0,0,0,1,0,0,0,3,0},
{0,0,1,0,0,0,0,6,8},
{0,0,8,5,0,0,0,1,0},
{0,9,0,0,0,0,4,0,0}
};
int LineNum = 9;
int RowAmount = 9;
for (int i = 0; i < LineNum; ++i)
{
for (int x = 0; x < RowAmount; ++x)
{
printf("%d ", &grid[i][x]);
}
printf("n");
}
}