Программа которою мне удалось сделать:
#include <iostream>
#include <ctime>
using namespace std;
//создаем динамический массив
int Ini_len_arr() {
cout << "Enter element of array :";
int //длина массива
cin >> n; cout << endl;
if (n < 0) { //если указали число <0, то выводим сообщение
cout << "Not correct,try again!";
Ini_len_arr();
}
return n;
}
//отображение массива
void print(int n, int* arr) {
for (int i = 0; i < n; i++) { //цикл прохождения по массиву
arr[i] = rand() % 30; //заполнение случайными числами
cout << arr[i] << " "; //вывод массива на экран
}
}
//сортировка пузырьком (понадобится для поиска двоичным методом)
void sort(int n, int* arr) {
int tmp; //выделения памяти для обмена
for (int j = 0; j < n - 1; j++) { //проход по массиву
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) { //сравнение 2х элементов
tmp = arr[i]; //если элементы стоят не правильно то меняем их местами
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
}
}
}
}
//поиск двоичным методом
void findbin(int n, int* arr, int key) {
int l = arr[0]; //обозначаем грани отсортированного массива l-мин h-макс значение
int h = arr[n-1];
int iter=0; // переменная для вычисления итераций
unsigned int start_time1 = clock(); //момент начала отчёта времени поиска
while (l <= h) { // цикл прекратится когда число будет найдено
iter++; // почёт итераций
int m = (l + h) / //поиск центра
if (arr[m] == key) { //когда число будет найдено на кране отобразится индекс элемента
cout << "Positions:t " << m + 1 << endl << "Iteratoins:t " << iter << endl;
break;
}
if (arr[m] < key) { //если сокращение массива указало на число меньше чем заданное
l = m + 1;
}
if (arr[m] > key) { //если сокращение массива указало на число больше чем заданное
h = m - 1;
}
}
unsigned int end_time1 = clock(); //момент остановки времени
unsigned int search_time1 = end_time1 - start_time1; //сколько времени прошло
cout << "Time:t " << search_time1 << "ms" << endl; //вывод времени
}
//поиск с барьером
void findbar(int arr[], int n, int key) {
int iter = 0;
if (arr[n - 1] != key) {//проверка не является ли заданный элемент не является последним
arr[n - 1] = key; //становление на последнее место элемент который ищем
int i = 0;
unsigned int start_time = clock();
while (arr[i] != key) //цикл продолжается пока не найдёт число
{
i++; //поиск индекса
iter++; //вычисление кол-во итераций
}
cout << "Positions:t " << i + 1 << endl << "Iteratoins:t " << iter << endl;
unsigned int end_time = clock();
unsigned int search_time = end_time - start_time;
cout << "Time:t " << search_time << "ms" << endl;
}
else {
cout << "Positions:t " << n << endl << "Iteratoins:t " << 1 << endl;
cout << "Time:t " << 1 << "ms" << endl;
}
}
//тело программы
void menu(int k, int* arr, int n) {
int key; //число которое будем искать
//выбор способа
if (k == 1) { //поиск с барьером
cout << "key ";
cin >> key;
findbar(arr, n, key);
}
else if (k == 2) { // поиск двоичным методом
cout << "key ";
cin >> key;
sort(n, arr);
findbin(n, arr, key);
}
else { // если выбор не соответствует вариантам
cout << "Not correct, try again: ";
cin >> k;
if (k >= 3) {
menu(k, arr, n); // просим повторить попытку
}
else {
menu(k, arr, n);
}
}
}
int main() {
int k;
//создание массива
int n = Ini_len_arr();
int* arr = new int[n];
//отображение массива
print(n, arr);
cout << endl;
//визуальное меню
cout << "Search:" << endl << "1-barier ; 2- binary" << endl << "your choise: ";
cin >> k; //выбор варианта поиска
menu(k, arr, n);
}
randomer 0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
||||||||||||
1 |
||||||||||||
02.10.2014, 16:33. Показов 2208. Ответов 6 Метки нет (Все метки)
Просьба помочь с пониманием указателей в функциях.
При моём текущем понимании указателей, правильная «конструкция»:
Но не пропускает nmake: «error C2100: недопустимое косвенное обращение»
компилируется, но программа «падает» Добавлено через 7 минут
0 |
4453 / 2687 / 483 Регистрация: 28.04.2012 Сообщений: 8,541 |
|
02.10.2014, 17:42 |
2 |
правильная «конструкция» Это по каким правилам она правильная? Добавлено через 1 минуту
Если пишу … компилируется, но программа «падает» А где проверка выхода за границу массива output?
0 |
0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
|
02.10.2014, 18:04 [ТС] |
3 |
Это по каким правилам она правильная? При моём текущем понимании указателей
А где проверка выхода за границу массива output? Не делал, потому что без этого работало в предыдущей версии основной программы…
0 |
153 / 148 / 66 Регистрация: 20.02.2014 Сообщений: 556 |
|
02.10.2014, 19:17 |
4 |
randomer, а что передается в output при вызове функции?
0 |
Модератор 11900 / 7272 / 1721 Регистрация: 25.07.2009 Сообщений: 13,314 |
|
02.10.2014, 20:26 |
5 |
там именно так работает Значит нужно смотреть, как в предыдущей версии устанавливалась переменная
FramePerInput и как задавался размер строки массива
dataOut и искать отличия.
j+(fr_num)*80 в качестве индекса внутри строки двумерного массива выглядит более, чем подозрительно. Такое чувство, что если убрать это +(fr_num)*80 то всё заработает…
0 |
randomer 0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
||||||||
03.10.2014, 10:51 [ТС] |
6 |
|||||||
Основная программа — wireshark.
вполне нормальная.
что и внесло сумятицу в голову.
0 |
0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
|
08.10.2014, 11:16 [ТС] |
7 |
Доброго всем времени суток.
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
08.10.2014, 11:16 |
Помогаю со студенческими работами здесь
int peremennaya=5461;… Ошибка «Access denied» error 5 при вызове VirtualQueryEx
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 7 |
I have a C application that I’ve created in VS2008. I am creating a mock creation function that overrides function references in a struct. However if I try and do this in a straight forward fashion with something like:
void *ptr = &(*env)->GetVersion;
*ptr = <address of new function>
then I get a «error C2100: illegal indirection» error as *ptr, when ptr is a void * seems to be a banned construct. I can get around it by using a int/long pointer as well, mapping that to the same address and modifying the contents of the long pointer:
*structOffsetPointer = &(*env)->GetVersion;
functionPointer = thisGetVersion;
structOffsetPointerAsLong = (long *)structOffsetPointer;
*structOffsetPointerAsLong = (long)functionPointer;
but I am concerned that using long or int pointers will cause problems if I switch between 32 and 64 bit environments.
So is there are easy way to disable this error? Assuming not, is either int or long 64 bits under win64?
asked Oct 14, 2008 at 22:13
David ArnoDavid Arno
42.6k16 gold badges85 silver badges131 bronze badges
Then how about:
void **ptr = (void **) &(*env)->GetVersion;
*ptr = <address of new function>
The right way to do this is to work with the type system, avoid all the casting and declare actual pointers to functions like:
typedef int (*fncPtr)(void);
fncPtr *ptr = &(*env)->GetVersion;
*ptr = NewFunction;
The above assumes GetVersion is of type fncPtr and NewFunction is declared as
int NewFunction(void);
answered Oct 14, 2008 at 22:33
1
When dereferencing a «void *», you are left with a «void» which is has no size (or really no type for that matter), so it doesn’t know how to assign something to it. It is the same as:
void blah = 0xdeadbabe; // let's assume a 32-bit addressing system
To add to my own response and give a solution, I would give it the proper type of a pointer to a function of the type GetVersion is. If GetVersion that your «env» struct field is pointing to is:
int GetVersion();
then you want:
int (**ptr)() = &(*env)->GetVersion;
answered Oct 14, 2008 at 22:25
Jim BuckJim Buck
20.4k11 gold badges55 silver badges74 bronze badges
3
Last time I played with void* & C under visual studio, VS didn’t play nicely.
Here are some information datapoints:
A pointer is always the size of the system word(8/16/32/64)…(unless you have segmented memory, which I’m assuming you don’t have). This is because it needs to point to anywhere in the memory space. For a von Neumann machine, a function pointer is going to be the same size as a data pointer, because data and code occupy the same memory space. This is not guaranteed under a Harvard architecture. I’m not familiar enough with Windows Vista to know if it programatically fakes out a Harvard architecture for security reasons.
I personally would not disable this error, just for the sake of letting the compiler do its job.
answered Oct 14, 2008 at 22:21
Paul NathanPaul Nathan
39.4k28 gold badges112 silver badges211 bronze badges
As mentioned, to store the address of a function in a pointer you should simply not do the indirection.
However, you also talk about being worried about the size of an int type that you might store a pointer into (which generally is not something you want to do unless you have a really good reason to).
If you want to hold a pointer in an int type for some reason, then on Windows a UINT_PTR
type (or uintptr_t
from stdint.h
if you have it) will hold most pointer types (I don’t think it’s necessarily large enough to hold some pointer-to-member types).
answered Oct 14, 2008 at 22:22
Michael BurrMichael Burr
332k50 gold badges531 silver badges756 bronze badges
2
Перейти к контенту
Программа которою мне удалось сделать:
#include <iostream>
#include <ctime>
using namespace std;
//создаем динамический массив
int Ini_len_arr() {
cout << "Enter element of array :";
int //длина массива
cin >> n; cout << endl;
if (n < 0) { //если указали число <0, то выводим сообщение
cout << "Not correct,try again!";
Ini_len_arr();
}
return n;
}
//отображение массива
void print(int n, int* arr) {
for (int i = 0; i < n; i++) { //цикл прохождения по массиву
arr[i] = rand() % 30; //заполнение случайными числами
cout << arr[i] << " "; //вывод массива на экран
}
}
//сортировка пузырьком (понадобится для поиска двоичным методом)
void sort(int n, int* arr) {
int tmp; //выделения памяти для обмена
for (int j = 0; j < n - 1; j++) { //проход по массиву
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) { //сравнение 2х элементов
tmp = arr[i]; //если элементы стоят не правильно то меняем их местами
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
}
}
}
}
//поиск двоичным методом
void findbin(int n, int* arr, int key) {
int l = arr[0]; //обозначаем грани отсортированного массива l-мин h-макс значение
int h = arr[n-1];
int iter=0; // переменная для вычисления итераций
unsigned int start_time1 = clock(); //момент начала отчёта времени поиска
while (l <= h) { // цикл прекратится когда число будет найдено
iter++; // почёт итераций
int m = (l + h) / //поиск центра
if (arr[m] == key) { //когда число будет найдено на кране отобразится индекс элемента
cout << "Positions:t " << m + 1 << endl << "Iteratoins:t " << iter << endl;
break;
}
if (arr[m] < key) { //если сокращение массива указало на число меньше чем заданное
l = m + 1;
}
if (arr[m] > key) { //если сокращение массива указало на число больше чем заданное
h = m - 1;
}
}
unsigned int end_time1 = clock(); //момент остановки времени
unsigned int search_time1 = end_time1 - start_time1; //сколько времени прошло
cout << "Time:t " << search_time1 << "ms" << endl; //вывод времени
}
//поиск с барьером
void findbar(int arr[], int n, int key) {
int iter = 0;
if (arr[n - 1] != key) {//проверка не является ли заданный элемент не является последним
arr[n - 1] = key; //становление на последнее место элемент который ищем
int i = 0;
unsigned int start_time = clock();
while (arr[i] != key) //цикл продолжается пока не найдёт число
{
i++; //поиск индекса
iter++; //вычисление кол-во итераций
}
cout << "Positions:t " << i + 1 << endl << "Iteratoins:t " << iter << endl;
unsigned int end_time = clock();
unsigned int search_time = end_time - start_time;
cout << "Time:t " << search_time << "ms" << endl;
}
else {
cout << "Positions:t " << n << endl << "Iteratoins:t " << 1 << endl;
cout << "Time:t " << 1 << "ms" << endl;
}
}
//тело программы
void menu(int k, int* arr, int n) {
int key; //число которое будем искать
//выбор способа
if (k == 1) { //поиск с барьером
cout << "key ";
cin >> key;
findbar(arr, n, key);
}
else if (k == 2) { // поиск двоичным методом
cout << "key ";
cin >> key;
sort(n, arr);
findbin(n, arr, key);
}
else { // если выбор не соответствует вариантам
cout << "Not correct, try again: ";
cin >> k;
if (k >= 3) {
menu(k, arr, n); // просим повторить попытку
}
else {
menu(k, arr, n);
}
}
}
int main() {
int k;
//создание массива
int n = Ini_len_arr();
int* arr = new int[n];
//отображение массива
print(n, arr);
cout << endl;
//визуальное меню
cout << "Search:" << endl << "1-barier ; 2- binary" << endl << "your choise: ";
cin >> k; //выбор варианта поиска
menu(k, arr, n);
}
randomer 0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
||||||||||||
1 |
||||||||||||
02.10.2014, 16:33. Показов 1954. Ответов 6 Метки нет (Все метки)
Просьба помочь с пониманием указателей в функциях.
При моём текущем понимании указателей, правильная «конструкция»:
Но не пропускает nmake: «error C2100: недопустимое косвенное обращение»
компилируется, но программа «падает» Добавлено через 7 минут
__________________ 0 |
4015 / 2617 / 475 Регистрация: 28.04.2012 Сообщений: 8,422 |
|
02.10.2014, 17:42 |
2 |
правильная «конструкция» Это по каким правилам она правильная? Добавлено через 1 минуту
Если пишу … компилируется, но программа «падает» А где проверка выхода за границу массива output? 0 |
0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
|
02.10.2014, 18:04 [ТС] |
3 |
Это по каким правилам она правильная? При моём текущем понимании указателей
А где проверка выхода за границу массива output? Не делал, потому что без этого работало в предыдущей версии основной программы… 0 |
153 / 148 / 66 Регистрация: 20.02.2014 Сообщений: 556 |
|
02.10.2014, 19:17 |
4 |
randomer, а что передается в output при вызове функции? 0 |
Модератор 11659 / 7172 / 1704 Регистрация: 25.07.2009 Сообщений: 13,142 |
|
02.10.2014, 20:26 |
5 |
там именно так работает Значит нужно смотреть, как в предыдущей версии устанавливалась переменная
FramePerInput и как задавался размер строки массива
dataOut и искать отличия.
j+(fr_num)*80 в качестве индекса внутри строки двумерного массива выглядит более, чем подозрительно. Такое чувство, что если убрать это +(fr_num)*80 то всё заработает… 0 |
randomer 0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
||||||||
03.10.2014, 10:51 [ТС] |
6 |
|||||||
Основная программа — wireshark.
вполне нормальная.
что и внесло сумятицу в голову. 0 |
0 / 0 / 0 Регистрация: 19.02.2014 Сообщений: 9 |
|
08.10.2014, 11:16 [ТС] |
7 |
Доброго всем времени суток. 0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
08.10.2014, 11:16 |
Помогаю со студенческими работами здесь
int peremennaya=5461;… Ошибка «Access denied» error 5 при вызове VirtualQueryEx
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 7 |
I have a C application that I’ve created in VS2008. I am creating a mock creation function that overrides function references in a struct. However if I try and do this in a straight forward fashion with something like:
void *ptr = &(*env)->GetVersion;
*ptr = <address of new function>
then I get a «error C2100: illegal indirection» error as *ptr, when ptr is a void * seems to be a banned construct. I can get around it by using a int/long pointer as well, mapping that to the same address and modifying the contents of the long pointer:
*structOffsetPointer = &(*env)->GetVersion;
functionPointer = thisGetVersion;
structOffsetPointerAsLong = (long *)structOffsetPointer;
*structOffsetPointerAsLong = (long)functionPointer;
but I am concerned that using long or int pointers will cause problems if I switch between 32 and 64 bit environments.
So is there are easy way to disable this error? Assuming not, is either int or long 64 bits under win64?
asked Oct 14, 2008 at 22:13
David ArnoDavid Arno
42.4k15 gold badges85 silver badges131 bronze badges
Then how about:
void **ptr = (void **) &(*env)->GetVersion;
*ptr = <address of new function>
The right way to do this is to work with the type system, avoid all the casting and declare actual pointers to functions like:
typedef int (*fncPtr)(void);
fncPtr *ptr = &(*env)->GetVersion;
*ptr = NewFunction;
The above assumes GetVersion is of type fncPtr and NewFunction is declared as
int NewFunction(void);
answered Oct 14, 2008 at 22:33
1
When dereferencing a «void *», you are left with a «void» which is has no size (or really no type for that matter), so it doesn’t know how to assign something to it. It is the same as:
void blah = 0xdeadbabe; // let's assume a 32-bit addressing system
To add to my own response and give a solution, I would give it the proper type of a pointer to a function of the type GetVersion is. If GetVersion that your «env» struct field is pointing to is:
int GetVersion();
then you want:
int (**ptr)() = &(*env)->GetVersion;
answered Oct 14, 2008 at 22:25
Jim BuckJim Buck
20.2k10 gold badges53 silver badges74 bronze badges
3
Last time I played with void* & C under visual studio, VS didn’t play nicely.
Here are some information datapoints:
A pointer is always the size of the system word(8/16/32/64)…(unless you have segmented memory, which I’m assuming you don’t have). This is because it needs to point to anywhere in the memory space. For a von Neumann machine, a function pointer is going to be the same size as a data pointer, because data and code occupy the same memory space. This is not guaranteed under a Harvard architecture. I’m not familiar enough with Windows Vista to know if it programatically fakes out a Harvard architecture for security reasons.
I personally would not disable this error, just for the sake of letting the compiler do its job.
answered Oct 14, 2008 at 22:21
Paul NathanPaul Nathan
39.3k28 gold badges112 silver badges209 bronze badges
As mentioned, to store the address of a function in a pointer you should simply not do the indirection.
However, you also talk about being worried about the size of an int type that you might store a pointer into (which generally is not something you want to do unless you have a really good reason to).
If you want to hold a pointer in an int type for some reason, then on Windows a UINT_PTR
type (or uintptr_t
from stdint.h
if you have it) will hold most pointer types (I don’t think it’s necessarily large enough to hold some pointer-to-member types).
answered Oct 14, 2008 at 22:22
Michael BurrMichael Burr
329k50 gold badges528 silver badges755 bronze badges
2
I have a C application that I’ve created in VS2008. I am creating a mock creation function that overrides function references in a struct. However if I try and do this in a straight forward fashion with something like:
void *ptr = &(*env)->GetVersion;
*ptr = <address of new function>
then I get a «error C2100: illegal indirection» error as *ptr, when ptr is a void * seems to be a banned construct. I can get around it by using a int/long pointer as well, mapping that to the same address and modifying the contents of the long pointer:
*structOffsetPointer = &(*env)->GetVersion;
functionPointer = thisGetVersion;
structOffsetPointerAsLong = (long *)structOffsetPointer;
*structOffsetPointerAsLong = (long)functionPointer;
but I am concerned that using long or int pointers will cause problems if I switch between 32 and 64 bit environments.
So is there are easy way to disable this error? Assuming not, is either int or long 64 bits under win64?
asked Oct 14, 2008 at 22:13
David ArnoDavid Arno
42.4k15 gold badges85 silver badges131 bronze badges
Then how about:
void **ptr = (void **) &(*env)->GetVersion;
*ptr = <address of new function>
The right way to do this is to work with the type system, avoid all the casting and declare actual pointers to functions like:
typedef int (*fncPtr)(void);
fncPtr *ptr = &(*env)->GetVersion;
*ptr = NewFunction;
The above assumes GetVersion is of type fncPtr and NewFunction is declared as
int NewFunction(void);
answered Oct 14, 2008 at 22:33
1
When dereferencing a «void *», you are left with a «void» which is has no size (or really no type for that matter), so it doesn’t know how to assign something to it. It is the same as:
void blah = 0xdeadbabe; // let's assume a 32-bit addressing system
To add to my own response and give a solution, I would give it the proper type of a pointer to a function of the type GetVersion is. If GetVersion that your «env» struct field is pointing to is:
int GetVersion();
then you want:
int (**ptr)() = &(*env)->GetVersion;
answered Oct 14, 2008 at 22:25
Jim BuckJim Buck
20.2k10 gold badges53 silver badges74 bronze badges
3
Last time I played with void* & C under visual studio, VS didn’t play nicely.
Here are some information datapoints:
A pointer is always the size of the system word(8/16/32/64)…(unless you have segmented memory, which I’m assuming you don’t have). This is because it needs to point to anywhere in the memory space. For a von Neumann machine, a function pointer is going to be the same size as a data pointer, because data and code occupy the same memory space. This is not guaranteed under a Harvard architecture. I’m not familiar enough with Windows Vista to know if it programatically fakes out a Harvard architecture for security reasons.
I personally would not disable this error, just for the sake of letting the compiler do its job.
answered Oct 14, 2008 at 22:21
Paul NathanPaul Nathan
39.3k28 gold badges112 silver badges209 bronze badges
As mentioned, to store the address of a function in a pointer you should simply not do the indirection.
However, you also talk about being worried about the size of an int type that you might store a pointer into (which generally is not something you want to do unless you have a really good reason to).
If you want to hold a pointer in an int type for some reason, then on Windows a UINT_PTR
type (or uintptr_t
from stdint.h
if you have it) will hold most pointer types (I don’t think it’s necessarily large enough to hold some pointer-to-member types).
answered Oct 14, 2008 at 22:22
Michael BurrMichael Burr
329k50 gold badges528 silver badges755 bronze badges
2
Я не понимаю эту ошибку (C2100: незаконное косвенное обращение). Я отметил три экземпляра — все они находятся внизу. Я искал в Интернете и знаю, что это связано с моими указателями, но после 8 часов на это я полностью потерялся. Здесь могут быть и другие ошибки, но я даже не могу сказать, потому что не могу его скомпилировать. Пожалуйста, помогите, и мне бы хотелось получить объяснение, которое я могу понять, чтобы я мог понять, что я делаю не так, в будущем.
// INCLUDE FILES
#include <stdio.h>
#include <string.h>
// PROGRAM CONSTANTS
#define MAX_MSG_LEN 81 // Maximum Message Length (Including /0 Character)
// FUNCTION PROTOTYPES
void printLength(int, int); // Function to Validate & Print Length of String
void printString(int, char); // Function to Print the String in Reverse
void writeToFile(int, char);
// GLOBAL VARIABLES
char input[MAX_MSG_LEN]; // Input String
int maxLength = MAX_MSG_LEN - 1; // Actual String Length (Not Including /0 Character)
char *ptr = input; // Character Pointer to String
int length = 0; // Length of Current String
int lcv = 0; // Loop Control Variable
void main()
{
FILE *ifp;
ifp = fopen("reverseString.txt", "w");
printf("nnEnter a String Between 1 and %d Characters: ", maxLength); // Prompts User to Enter a String Less Than 80
gets(input); // Receives the Inputted String from the User
length = strlen(input); // Counts the Length of the Inputted String & Assigns the Number to the "length" Variable
printLength(length, maxLength);
printString(length, *ptr);
writeToFile(length, *ptr);
}
void printLength(int length, int maxLength)
{
if(length > maxLength)
{
printf("nnThe Maximum Length of %d Characters was Exceeded!", maxLength);
printf("nProgram Terminated...nn");
exit(0);
}
printf("nnThe Length of the Input String was: %dn", length); // Prints the Length of the Inputted String
}
void printString(int length, char ptr)
{
for(; lcv < length; lcv++)
{
ptr++;
}
length = lcv;
printf("nThe String in Reverse: ");
for(ptr--; length > 0; length--)
{
printf("%c", *ptr); // HERE IS ONE INSTANCE OF C2100
*ptr--; // HERE IS ONE INSTANCE OF C2100
}
printf("nn");
return;
}
void writeToFile(int length, char ptr)
{
FILE *ifp;
ifp = fopen("reverseString.txt", "w");
fprintf(ifp, "%c", *ptr); // HERE IS ONE INSTANCE OF C2100
fclose(ifp);
}
2 ответа
Лучший ответ
В вашем коде неправильный синтаксис. Вам необходимо изменить декларацию и определение (я)
void printString(int, char);
К
void printString(int, char*);
И назовите это как
printString(length, ptr);
То же самое и с функцией writeToFile()
.
В противном случае, с текущим кодом, в функциях printString()
и writeToFile()
, с определением, подобным char ptr
, ptr
не является типом указателя, который можно разыменовать.
Это сказало,
-
Никогда не используйте
gets()
, у него проблемы с переполнением буфера, используйтеfgets()
вместо этого. -
Всегда проверяйте возвращаемое значение из
fopen()
перед использованием возвращаемого указателя, чтобы гарантировать успешность вызова. -
Чтобы соответствовать стандартам,
void main()
должно быть как минимумint main(void)
.
3
Sourav Ghosh
25 Янв 2016 в 07:49
2) включить заголовок {{X0}} для поддержки функции {{X1}}, поскольку определение {{X2}} доступно в {{X3}}…
1) Попробуйте изменить объявления функций printString()
и writeToFile()
, как предложил Саурав Гош.
2) включить заголовок stdlib.h
для поддержки функции exit()
, поскольку определение exit()
доступно в stdlib.h
3) Измените void main(){/* your code*/}
на int main(){/* your code */}
Я внес указанные выше изменения, и он успешно скомпилирован на моей машине.
2
SKD
25 Янв 2016 в 08:55
Пожалуйста, посмотрите на следующий код
double RTMotionDetector::getMSE(Mat I1, Mat I2)
{
Mat *s1;
cv::absdiff(*I1, *I2, *s1); // |I1 - I2|
*s1->convertTo(*s1, CV_32F); // cannot make a square on 8 bits
*s1 = s1->mul(*s1); // |I1 - I2|^2
Scalar s = sum(*s1); // sum elements per channel
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
if( sse <= 1e-10) // for small values return zero
return 0;
else
{
double mse =sse /(double)(I1.channels() * I1.total());
return mse;
// Instead of returning MSE, the tutorial code returned PSNR (below).
//double psnr = 10.0*log10((255*255)/mse);
//return psnr;
}
}
Вот как это называется
getMSE(*currentGrey,*next)
Вот как currentGrey
а также next
Матовые объекты инициализируются
Mat *current, *currentGrey
Когда я запускаю вышеупомянутый метод, я получаю ошибку error C2100: illegal indirection
,
Ошибка исходит из этих двух строк
cv::absdiff(*I1, *I2, *s1); // |I1 - I2|
*s1->convertTo(*s1, CV_32F); // cannot make a square on 8 bits
Я сделал все возможное, чтобы решить эту проблему, но не удалось. В любом случае, я довольно новичок в программировании Windows. Пожалуйста помоги.
0
Решение
Задача ещё не решена.
Другие решения
Других решений пока нет …
3 ответа
Эта структура не имеет конструктора. Код, который вы хотите, следующий:
struct Conf {
unsigned int id;
int test1;
int test2;
int test3;
int test4;
int test5;
int test6;
};
Conf cf = {
0,
0,
0,
0,
0,
0,
0
}; // Array initializer for struct type.
James Whyte
12 апр. 2018, в 22:49
Поделиться
Снимите круглые кронштейны. Компилятор пытается использовать конструктор.
#include <iostream>
struct Conf {
unsigned int id;
int test1;
int test2;
int test3;
int test4;
int test5;
int test6;
};
Conf cf { // Curlies only
1u,
0,
0,
0,
0,
0,
7
};
int main() {
std::cout << cf.id << " " << cf.test6 << 'n';
return 0;
}
Jive Dadson
12 апр. 2018, в 22:42
Поделиться
Я считаю, что проблема заключается в наиболее неприятном анализе, где
Conf cf({..});
понимается как функция с временным параметром Conf
в качестве параметра.
Температура Conf
объект список инициализируется, как показано ниже.
От dcl.init#17.1
:
Если инициализатор представляет собой (не заключенный в скобки) бит-init-list или is = braced-init-list, объект или ссылка инициализируются по списку.
struct S2 {
int m1;
double m2, m3;
};
S2 s21 = { 1, 2, 3.0 }; // OK
S2 s22 { 1.0, 2, 3 }; // error: narrowing
Так что просто list-initialize cf
напрямую:
Conf cf {...};
codekaizer
12 апр. 2018, в 23:00
Поделиться
Ещё вопросы
- 1Spring использует провайдера анонимной аутентификации для использования гостевого пользователя
- 1Оберточная попытка поймать что-то из интернета, через некоторое время
- 1Схема URL-адреса Bing Map для Windows Phone 8.1
- 0Перезагрузить страницу, чтобы показать вставленные элементы пользовательского интерфейса jQuery?
- 1Как правильно использовать org.w3c.xml.Document # importNode
- 0Как получить восходящий порядок значений массива в seInterval?
- 0проблема, связанная с методом POST и GET в HTML
- 1libGDX не будет работать на Android
- 0preg для извлечения из тега h1
- 1Сборка JSON безопасно
- 1Как использовать функцию C со сложными типами в Python?
- 0Проблема в сборке выпуска Visual Studio 2012
- 1Отображение URL Jax-RS API
- 1Предотвратить масштабирование графика D3
- 0Не могу установить переменную вне php foreach statment
- 0C ++ std :: list <T> :: iterator Имеет ли итератор доступ к функциям-членам <T>?
- 0Javascript многопоточность обоих оконных фокусов
- 1Противоречивые методы на множественном наследовании интерфейса
- 1Уведомления и AlarmManager — отмена будильника, который я установил
- 1response.setContentType ( «ПРИМЕНЕНИЕ / ОКТЕТ-ПОТОК»)
- 0Вывести каждое слово в строке на новую строку
- 1Ошибка колбы с сообщением dill.dill при загрузке сохраненного файла
- 0AngularJS: Задержка исчезает с $ timeout
- 0Сохранение неизвестного количества целых чисел, не занимая слишком много времени / памяти
- 0Программа C ++ Win32 неконсольное приложение с Windows taskschd.msc, не работает
- 0Передача входных данных между текстовыми полями HTML
- 0Синтаксическая ошибка триггера MySQL в БД Мария
- 0Как изменить стиль текста вкладки браузера с помощью Javascript?
- 1-cp получает честь, когда мы запускаем исполняемый файл jar
- 1SurfaceView отображает подачу камеры в сторону
- 0Обновление WAMP до php 5.5.12 остановило работу всех моих операторов подготовки SQL
- 1Ошибка TypeE на pickle.load с классом, производным от SimpleNamespace
- 0Как я могу преобразовать дату и время: 1518427800 в чч: мм: сс дд / мм / гггг в node.js?
- 0Выбор даты открытия через HTML iOS
- 0$ http в приложении Ionic не ловит ошибки
- 0как работает указатель при перемещении на массив целых
- 0jquery не может вызвать .dialog (‘moveToTop’) в отфильтрованном списке диалогов
- 0Как вы можете остановить границы элементов ячейки таблицы, перекрывающих область заполнения ячейки?
- 0Сокращение количества условий для всех возможностей
- 1отправить значения TextBox из FormB в DataGridView в FormA
- 0Выберите отдельные значения в одну результирующую запись в виде списка через запятую
- 0JQuery назначить пустое входное значение переменной
- 0Эффективный поиск в хэш-таблице без использования ключа
- 0Разбор ответа JSON в jQuery только для первого значения
- 1Android VideoView LinearLayout LayoutParams
- 1Использование cumcount () с dups
- 0Вставить в таблицу, используя среднее значение другой таблицы
- 0mariaDB — не могу связаться с php / страница просто пуста [дубликаты]
- 0Избегайте разметки
- 0Интерфейс Jquery с изменяемым размером и размерами блока: проблема «рамки»
Я не понимаю эту ошибку (C2100: незаконное косвенное обращение). Я отметил три экземпляра — все они находятся внизу. Я искал в Интернете и знаю, что это связано с моими указателями, но после 8 часов на это я полностью потерялся. Здесь могут быть и другие ошибки, но я даже не могу сказать, потому что не могу его скомпилировать. Пожалуйста, помогите, и мне бы хотелось получить объяснение, которое я могу понять, чтобы я мог понять, что я делаю не так, в будущем.
// INCLUDE FILES
#include <stdio.h>
#include <string.h>
// PROGRAM CONSTANTS
#define MAX_MSG_LEN 81 // Maximum Message Length (Including /0 Character)
// FUNCTION PROTOTYPES
void printLength(int, int); // Function to Validate & Print Length of String
void printString(int, char); // Function to Print the String in Reverse
void writeToFile(int, char);
// GLOBAL VARIABLES
char input[MAX_MSG_LEN]; // Input String
int maxLength = MAX_MSG_LEN - 1; // Actual String Length (Not Including /0 Character)
char *ptr = input; // Character Pointer to String
int length = 0; // Length of Current String
int lcv = 0; // Loop Control Variable
void main()
{
FILE *ifp;
ifp = fopen("reverseString.txt", "w");
printf("nnEnter a String Between 1 and %d Characters: ", maxLength); // Prompts User to Enter a String Less Than 80
gets(input); // Receives the Inputted String from the User
length = strlen(input); // Counts the Length of the Inputted String & Assigns the Number to the "length" Variable
printLength(length, maxLength);
printString(length, *ptr);
writeToFile(length, *ptr);
}
void printLength(int length, int maxLength)
{
if(length > maxLength)
{
printf("nnThe Maximum Length of %d Characters was Exceeded!", maxLength);
printf("nProgram Terminated...nn");
exit(0);
}
printf("nnThe Length of the Input String was: %dn", length); // Prints the Length of the Inputted String
}
void printString(int length, char ptr)
{
for(; lcv < length; lcv++)
{
ptr++;
}
length = lcv;
printf("nThe String in Reverse: ");
for(ptr--; length > 0; length--)
{
printf("%c", *ptr); // HERE IS ONE INSTANCE OF C2100
*ptr--; // HERE IS ONE INSTANCE OF C2100
}
printf("nn");
return;
}
void writeToFile(int length, char ptr)
{
FILE *ifp;
ifp = fopen("reverseString.txt", "w");
fprintf(ifp, "%c", *ptr); // HERE IS ONE INSTANCE OF C2100
fclose(ifp);
}
2 ответа
Лучший ответ
В вашем коде неправильный синтаксис. Вам необходимо изменить декларацию и определение (я)
void printString(int, char);
К
void printString(int, char*);
И назовите это как
printString(length, ptr);
То же самое и с функцией writeToFile()
.
В противном случае, с текущим кодом, в функциях printString()
и writeToFile()
, с определением, подобным char ptr
, ptr
не является типом указателя, который можно разыменовать.
Это сказало,
-
Никогда не используйте
gets()
, у него проблемы с переполнением буфера, используйтеfgets()
вместо этого. -
Всегда проверяйте возвращаемое значение из
fopen()
перед использованием возвращаемого указателя, чтобы гарантировать успешность вызова. -
Чтобы соответствовать стандартам,
void main()
должно быть как минимумint main(void)
.
3
Sourav Ghosh
25 Янв 2016 в 07:49
2) включить заголовок {{X0}} для поддержки функции {{X1}}, поскольку определение {{X2}} доступно в {{X3}}…
1) Попробуйте изменить объявления функций printString()
и writeToFile()
, как предложил Саурав Гош.
2) включить заголовок stdlib.h
для поддержки функции exit()
, поскольку определение exit()
доступно в stdlib.h
3) Измените void main(){/* your code*/}
на int main(){/* your code */}
Я внес указанные выше изменения, и он успешно скомпилирован на моей машине.
2
SKD
25 Янв 2016 в 08:55