Code: Select all
char * aux = strcpy(aux,&c);
Moderator: Board moderators
Code: Select all
char * aux = strcpy(aux,&c);
Code: Select all
0823025713
Code: Select all
1234567890
Code: Select all
unsigned int size =strlen(line);
while (i != size+1)
{
Code: Select all
0-89237-010-6
0-89237-010 -6
0-1-3-1-6-2-9-5-9-X
0abc-13dfasdfa-162959-X
0-13-162959-X // leading/trailing spaces
0-13-162959-X 0-13-162959-X
0-13-162959-X1
-------0-89237-010-6--------
0-89237-010-6XXXX
0-89237-010-6-150
// blank line
0-89237-010- 6 TEST
Code: Select all
0-89237-010-6 is correct.
0-89237-010 -6 is correct.
0-1-3-1-6-2-9-5-9-X is correct.
0abc-13dfasdfa-162959-X is correct.
0-13-162959-X is correct.
0-13-162959-X 0-13-162959-X is incorrect.
0-13-162959-X1 is incorrect.
-------0-89237-010-6-------- is correct.
0-89237-010-6XXXX is incorrect.
0-89237-010-6-150 is incorrect.
is incorrect.
0-89237-010- 6 TEST is incorrect.
Code: Select all
#include<stdio.h>
int isdigit(char c)
{
switch(c)
{
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
//case 'x': return 10;
case 'X': return 10;
default: return -1;
}
}
int main()
{
int i=0,n;
char c;
int s1 =0, s2 =0;
while((c=getchar())!=EOF)/*till EOF*/
{
i=0;
s1=0;
s2=0;
while(c!='\n' && c!=EOF)/*new ISBN*/
{
if(c != ' ')/*Leave out the spaces, print everything else*/
printf("%c",c);
if((n=isdigit(c))!= -1) /*If character is a digit*/
{
i++; /*count digits*/
s1 += n; /*Partial Sums*/
s2 += s1;
}
c = getchar();
}
if(i==10 && s2%11 == 0)
printf(" is correct.\n");
else /*If i><10 or s2%11 != 0*/
printf(" is incorrect.\n");
}
return 0;
}
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
char str[81],str1[80],str2[80];
int x,p,flag,i,fal,S[80],S2[80],a,l1,l2,arr[80],N,N1,N2,arr2[80];
while(gets(str))
{
l1=strlen(str);
if(l1==0)flag=0;
fal=0;
a=0;
p=0;
x=0;
for(i=0;i<l1;i++)
{
if(a==10 && str[i]=='X' && x!=1)
{
arr[a]=10;
x=1;
flag=1;
}
if(isdigit(str[i])>0)
{
arr[a]=(str[i]-'0');
a++;
flag=1;
}
if(isspace(str[i])==0)
{str1[p]=str[i];p++;}
else fal++;
}
str1[p]='\0';
if(fal==(l1-1))flag=0;
if(a>10)flag==0;
if(flag==1)
{
S[0]=arr[0];
S2[0]=S[0];
for(i=1;i<a;i++)
{
S[i]=S[i-1]+arr[i];
S2[i]=S2[i-1]+S[i];
}
sprintf(str2,"%d",S2[i]);
l2=strlen(str2);
N1=0;
for(i=0;i<l2;i++)
{
arr2[i]=(str2[i]-'0');
}
for(i=0;i<l2;i+=2)
{
N1=N1+arr2[i];
}
N2=0;
for(i=1;i<l2;i+=2)
{
N2=N2+arr2[i];
}
N=0;
N=abs(N1-N2);
if((N%11)==0)
printf("%s is correct.\n",str1);
else if((N%11)!=0){printf("%s is incorrect.\n",str1);}
}
else if(flag==0){printf("%s is incorrect.\n",str1);}
}
return 0;
}
I think you have printed the trailing spaces of the input string and getting PE.Karthekeyan wrote:Here's my code that gives presentation error with oj.... is it because of the endl on seeing eof??