#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include<cstdio>
#include <stdint.h>
#define length 20
#include <iostream>
usingnamespace std;
int main()
{
char s[length];
char adad[10];
char alamat[10];
int dec;
cout << "Enter a string" << endl;
//read in the users data from the input stream and ends by enter
cin.get(s,'\n');
//Display a message made up of two strings and the user data
cout << "ha ha! you entered the string " << s << endl;
/*************initializing arrays************/
for (int j=0 ; j<length ; j++)
{
if (ispunct(s[j]))
{
for (int k=0;k<10;k++)
adad[k]=s[j];
}
else
{
for (int l=0;l<10;l++)
alamat[l]=s[j];
}
}
/**********preview arrays*************/
for (int m=0;m<10; m++)
printf("%c" , adad[m]);
for (int n=0; n<10; n++)
printf("%c" , alamat[n]);
scanf("%d" , dec);
printf("finally %d" , dec);
return 0;
}
the error is error C2334: unexpected token(s) preceding '{'; skipping apparent function body
iostream likely uses the identifier "length" for many other things. Possibly function and/or variable names. By defining a macro you are unwittingly replacing everything in iostream.
Do not use #define to declare constants
The solution here is to get rid of the define and make it a constant:
1 2
//#define length 20 // bad
constr int length = 20; // good
Why on earth do you use scanf and printf? If it's your choice then I pass but if it's not consider other ways.
How old is your compiler anyway? You are using string.h for example. Why? Headers in C++ don't use .h extension. Check it out. You also include many unnecessary header files. Like #include <stdio.h> and also #include<cstdio> . These are the same thing. The first is used in C the second in C++.
Your line 52 won't work. Use scanf("%d" , &dec);
When you use const defined in preprocessor declare them with capital letters. There is probable another length issue in your system.
Use #define LENGTH 20 instead
// Length210120120048.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include<cstdio>
//#include <stdint.h>
#include <iostream>
#define LENGHT 20
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char s[LENGHT];
char adad[10];
char alamat[10];
int dec = 0 ;
cout << "Enter a string" << endl;
//read in the users data from the input stream and ends by enter
cin.getline(s,'\n');
//Display a message made up of two strings and the user data
cout << "ha ha! you entered the string " << s << endl;
/*************initializing arrays************/
for (int j=0 ; j<LENGHT ; j++)
{
if (ispunct(s[j]))
{
for (int k=0;k<10;k++)
adad[k]=s[j];
}
else
{
for (int l=0;l<10;l++)
alamat[l]=s[j];
}
}
/**********preview arrays*************/
for (int m=0;m<10; m++)
cout <<adad[m];
for (int n=0; n<10; n++)
cout<<alamat[n];
cin>>dec;
cout<<"\nfinally " <<dec;
return 0;
}