Модераторы: Daevaorn
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> помогите переделать код из С++ в С, пожалуйста... 
V
    Опции темы
Splendid
Дата 6.8.2008, 13:24 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 256
Регистрация: 1.8.2007
Где: Беларусь, Минск

Репутация: нет
Всего: нет



Есть код на С++, надо чистый С. Пыталась исправлять ошибки, но чем больше я это делаю, тем больше ошибок он выдает...поэтому привожу изначальный не исправленный на С++. Пожалуйста, помогите разобраться!

Код





Это сообщение отредактировал(а) Splendid - 6.8.2008, 14:41
PM MAIL   Вверх
mrbrooks
Дата 6.8.2008, 13:29 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


трололомен
****


Профиль
Группа: Завсегдатай
Сообщений: 4259
Регистрация: 4.10.2006
Где: Дол Гулдур

Репутация: 2
Всего: 306



Да вроде все ничего - только убрать надо 
Код

#include <cmath> //поменять на #include <math.h>
#include <iostream>

И остальным хидарам добавит .h

Добавлено через 3 минуты и 1 секунду
добавить 
Код

#include <stdio.h>


в общем код на мой взгляд удовлетворяет С
PM MAIL   Вверх
Alek86
Дата 6.8.2008, 13:40 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Завсегдатай
Сообщений: 1299
Регистрация: 30.1.2007
Где: Киев

Репутация: 21
Всего: 25



ссылок в си нету


--------------------
user posted image    user posted image
PM MAIL   Вверх
mrbrooks
Дата 6.8.2008, 13:47 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


трололомен
****


Профиль
Группа: Завсегдатай
Сообщений: 4259
Регистрация: 4.10.2006
Где: Дол Гулдур

Репутация: 2
Всего: 306



Цитата(Alek86 @ 6.8.2008,  13:40)
ссылок в си нету

тьфу ты блин. точно.  да надо переходить на указатели.
PM MAIL   Вверх
Splendid
Дата 6.8.2008, 13:55 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 256
Регистрация: 1.8.2007
Где: Беларусь, Минск

Репутация: нет
Всего: нет



а как на указатели граммотно перейти?

Добавлено через 3 минуты и 38 секунд
и я так понимаю, что от заголовочных файлов должно остаться только 

Код

#include <math.h>
#include <stdio.h>


ибо если оставить 


Код

#include <map.h>
#include <vector.h>


то пишет, что не видит их
PM MAIL   Вверх
mrbrooks
Дата 6.8.2008, 14:06 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


трололомен
****


Профиль
Группа: Завсегдатай
Сообщений: 4259
Регистрация: 4.10.2006
Где: Дол Гулдур

Репутация: 2
Всего: 306



да так и есть имхо. еще надо исправить функции 
Код

void mulmod (int & a, int b, const & n);
void transform_num (int n, int & p, int & q);
int lucas_selfridge (const & n);

а именно вместо ссылок использовать указатели.

Код

void mulmod (int  *a, int b, const int *n);
void transform_num (int n, int * p, int * q);
int lucas_selfridge (const int * n);


Код

void mulmod (int * a, int b, const int * n)
{
    // наивная версия, годится только для длинной арифметики
    *a *= b;
    *a %= *n;
}


И надо их изменить в этом же духе
PM MAIL   Вверх
Splendid
Дата 6.8.2008, 14:21 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 256
Регистрация: 1.8.2007
Где: Беларусь, Минск

Репутация: нет
Всего: нет



mrbrooks, изменила, но чувство у меня, что я неправильно додумаласьsmile) Ибо очень много ошибок повылазило:

Код

ompiling...
1.c
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(8) : warning C4244: 'initializing' : conversion from 'double ' to 'int ', possible loss of data
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(19) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(23) : error C2065: 'result' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(119) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(120) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(120) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(120) : error C2143: syntax error : missing ')' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(120) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(120) : error C2065: 'd_sign' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(120) : error C2059: syntax error : ')'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(121) : error C2065: 'd_abs' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(121) : error C2105: '++' needs l-value
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(121) : error C2143: syntax error : missing ';' before '{'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(122) : error C2065: 'dd' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(123) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(124) : error C2065: 'g' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(127) : error C2143: syntax error : missing ')' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(127) : error C2198: 'jacobi' : too few actual parameters
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(133) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(137) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(138) : error C2065: 'n_1' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(139) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(140) : error C2065: 's' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(140) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(140) : warning C4024: 'transform_num' : different types for formal and actual parameter 2
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(140) : error C2065: 'd' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(140) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(140) : warning C4024: 'transform_num' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(144) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2143: syntax error : missing ')' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2065: 'bit' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2065: 'bits' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : warning C4552: '<' : operator has no effect; expected operator with side-effect
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(151) : error C2143: syntax error : missing ';' before ')'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(154) : error C2065: 'v2m' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(154) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(154) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(154) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(154) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(155) : error C2065: 'qm2' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(158) : error C2065: 'qm' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(158) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(158) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(158) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(158) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(164) : error C2065: 'u2m' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(165) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(165) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(165) : error C2065: 'v' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(165) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(165) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(167) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(167) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(167) : error C2065: 'u' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(167) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(167) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(169) : error C2143: syntax error : missing ';' before 'type'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(170) : error C2065: 't3' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(171) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(171) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(171) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(171) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(172) : error C2065: 't4' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(173) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(173) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(173) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(173) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(174) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(174) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(174) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(174) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(187) : error C2065: 'qkd' : undeclared identifier
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(187) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(187) : warning C4024: 'mulmod' : different types for formal and actual parameter 1
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(187) : warning C4047: 'function' : 'const int *' differs in levels of indirection from 'const int '
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(187) : warning C4024: 'mulmod' : different types for formal and actual parameter 3
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(192) : error C2059: syntax error : 'if'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(196) : error C2099: initializer is not a constant
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(197) : error C2143: syntax error : missing '{' before '*='
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(197) : error C2059: syntax error : '*='
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(198) : error C2059: syntax error : 'for'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(198) : error C2143: syntax error : missing '{' before '<'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(198) : error C2059: syntax error : '<'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(198) : error C2059: syntax error : '++'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(198) : error C2059: syntax error : ')'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(216) : error C2059: syntax error : 'return'
F:\Program Files\Microsoft Visual Studio\MyProjects\test_na_C\1.c(218) : error C2059: syntax error : '}'
Error executing cl.exe.

1.exe - 52 error(s), 38 warning(s)



Добавлено через 7 минут и 33 секунды
mrbrooks, все, сделала все, как Вы сказали, все исправила, все работает - спасибо Вам огромное!
И всем принимавшим участие - Спасибо! Тему можно закрытьsmile
PM MAIL   Вверх
beliaf
Дата 6.8.2008, 14:39 (ссылка) |    (голосов:1) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 31.7.2008
Где: N. Chelny

Репутация: нет
Всего: нет



ИМХО, лучший способ переделать код, это понять как все это работает на плюсах и самому написать тоже самое на сишниге))
PM MAIL ICQ Jabber   Вверх
mrbrooks
Дата 6.8.2008, 15:06 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


трололомен
****


Профиль
Группа: Завсегдатай
Сообщений: 4259
Регистрация: 4.10.2006
Где: Дол Гулдур

Репутация: 2
Всего: 306



Цитата(Splendid @ 6.8.2008,  14:21)
mrbrooks, все, сделала все, как Вы сказали, все исправила, все работает - спасибо Вам огромное!
И всем принимавшим участие - Спасибо! Тему можно закрытьsmile

Да не за что. А тему собственно сама можешь закрыть  smile 
PM MAIL   Вверх
Lazin
Дата 6.8.2008, 15:15 (ссылка) |    (голосов:1) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 3820
Регистрация: 11.12.2006
Где: paranoid oil empi re

Репутация: 41
Всего: 154



как вариант можно было-бы собрать плюсовый код в библиотеку и подключить к сишному проекту, только нужно, что-бы экспортировались функции а не классы...
PM MAIL Skype GTalk   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "С++:Общие вопросы"
Earnest Daevaorn

Добро пожаловать!

  • Черновик стандарта C++ (за октябрь 2005) можно скачать с этого сайта. Прямая ссылка на файл черновика(4.4мб).
  • Черновик стандарта C (за сентябрь 2005) можно скачать с этого сайта. Прямая ссылка на файл черновика (3.4мб).
  • Прежде чем задать вопрос, прочтите это и/или это!
  • Здесь хранится весь мировой запас ссылок на документы, связанные с C++ :)
  • Не брезгуйте пользоваться тегами [code=cpp][/code].
  • Пожалуйста, не просите написать за вас программы в этом разделе - для этого существует "Центр Помощи".
  • C++ FAQ

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Earnest Daevaorn

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.0608 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.