samedi 25 avril 2015

Produce incorrect value from a given correct value and set of invalid chars


I need to create the Invalid values for a given attribute like ID that has only correct value ASP-101. All values other than this like ASP-101! or ASP-101# or !SP-101 or ASP+101 or ASP-10# .. etc are incorrect. A file with invalid chars is given, Special characters file invalidchars.txt has :

#
$
%
^
&
*
(
)
-
_
+
=
{
}
[
]
\
/
|
:
;
"
'
?
>
<
.
,

 /

and main.c has the code:

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>

int main()
{

    FILE *fp_char,*fp_test;
    char aspid[] = "ASP-101";
    char *asp;
    char arr[2];
    char invalid_chars;


    fp_char = fopen("invalidchars.txt","r");
    fp_test = fopen("test.txt","w");

    if(fp_test == NULL || fp_char == NULL)
    {
        printf("cannot open file.\n");
        return;
    }


    asp = (char *)malloc(sizeof(char)*(strlen(aspid)+2));
    strcpy(asp,aspid);


    while((invalid_chars = fgetc(fp_char)) != EOF) 
    {
        arr[0]=invalid_chars;
        strcat(asp,arr);
        fprintf(fp_test,"%s\t",asp);
        memset(asp,0,strlen(aspid));
        strcpy(asp,aspid);
    }

    fclose(fp_char);
    fclose(fp_test);
    return 0;
}

In this I have covered the appending special char in the end and produce incorrect value. But how to generate others cases for incorrect value for attribute.

Somebody help is admired a lot . Any idea will help me to do this......


Aucun commentaire:

Enregistrer un commentaire