Перевести код из C++ в C

  • Автор темы Автор темы Future Lover
  • Дата начала Дата начала
F

Future Lover

Привет. Надо перевести код на С из С++. Может кто-нибудь подсказать что тут поменять?
Код:
// temp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int my_strlen( const char *sz ) {
const char *szEnd = sz;
while( *szEnd++ ) {; }
return int( szEnd - sz - 1 );
}


size_t getPtrSize( char *ptr )
{
return sizeof( ptr );
}


char* compress( char str[] )
{
int str_size = my_strlen( str );

char *res;
res = new char[ int ( str_size*3/2 ) ];

int i;
int j = 0;
int count = 0;

for ( i = 0; i < str_size; i++ )
{
if ( str[ i ] != str[ i + 1 ] )
{
if ( count > 0 )
{
res[ j ] = '#';
res[ j + 1 ] = str[ i ];
res[ j + 2 ] = count + 49;
j += 3;
count = 0;
}
else
{
res[ j ] = str[ i ];
j += 1;
}			
}
else
count++;
}
res[ j ] = '\0';
return res;
}

int _tmain(int argc, _TCHAR* argv[])
{
char *str;
str = new char[100];
cout << "Enter string: ";
cin >> str;
cout << "Compressed string: " << compress( str ) << "\n";

int i, j;

int *array_a;
int size_a;
cout << "Enter array A dimension: ";
cin >> size_a;
array_a = new int[ size_a ];
cout << "Enter " << size_a << " elements: ";
for ( i = 0; i < size_a; i ++ )
cin >> array_a[ i ];


int *array_b;
int size_b;
cout << "Enter array B dimension: ";
cin >> size_b;
array_b = new int[ size_b ];
cout << "Enter " << size_b << " elements: ";
for ( i = 0; i < size_b; i ++ )
cin >> array_b[ i ];

int count = 0;
for ( i = 0; i < size_a; i ++ )
{
if ( array_a[ i ] == array_a[ i + 1 ] )
continue;	
for ( j = 0; j < size_b; j++ )
if ( array_a[ i ] == array_b[ j ] )
{
count++;
break;
}
}
cout << "Result: " << count << "\n";
cin >> count;
return 0;
}
 
Вам нужно сделать немного
1.вместо new использовать malloc
2.вместо cin scanf
3.вместо cout printf
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!