Read entry and store specific information in C

0

I want to identify all 32 reserved words of C written in an entry that simulates a C code, but it is not storing all and I do not know what is wrong, obs stores only if it appears and what not the number of times it appears. Here is the code and an example input and output

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ja_lido(char reser[32][10] , char lido[10],int t){
    int i,j=0,k=0;
    for (i=0;i<=t;i++){
        if (strcmp(reser[i],lido) == 0){
            return 0;
        }
    }
    return 1;
}
int main(){
    char reservadas[32][10] = {"auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while"};
    char res[32][10],lido='a',pal[30];
    int n=0,i,k,j=0;
    for(i=0;i<30;i++){
        pal[i] = '
#include<stdlib>
#include<math.h>

struct TreeNode {   
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

int maxDepth(TreeNode* A){

    if( A==NULL ){
        return 0;
    }else{
    return max(1+maxDepth(A->left),1+maxDepth(A->right));    
    }

}

int main(){

    struct TreeNode *root = new TreeNode(1); 
    root->left = new TreeNode(2);
    root->right = new TreeNode(3); 
    root->left->left = new TreeNode(4);
    root->left->right = new TreeNode(5);    

    int count = maxDepth(root);

    printf("%d",count);

    return 0;
}
'; } while( lido != EOF){ lido = getchar(); if (lido != '(' && lido != ')' && lido != '{' && lido != '}' && lido != ';' && lido != '-' && lido != ' '){ pal[j] = lido; j++; for(i=0;i<32;i++){ if (strcmp(pal,reservadas[i]) == 0){ if(ja_lido(res,pal,n)){ strcpy(res[n],pal); n++; for(k=0;k<j;k++){ pal[k] = '
int else
'; } j=0; } } } } else{ for(k=0;k<j;k++){ pal[k] = '
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ja_lido(char reser[32][10] , char lido[10],int t){
    int i,j=0,k=0;
    for (i=0;i<=t;i++){
        if (strcmp(reser[i],lido) == 0){
            return 0;
        }
    }
    return 1;
}
int main(){
    char reservadas[32][10] = {"auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while"};
    char res[32][10],lido='a',pal[30];
    int n=0,i,k,j=0;
    for(i=0;i<30;i++){
        pal[i] = '
#include<stdlib>
#include<math.h>

struct TreeNode {   
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

int maxDepth(TreeNode* A){

    if( A==NULL ){
        return 0;
    }else{
    return max(1+maxDepth(A->left),1+maxDepth(A->right));    
    }

}

int main(){

    struct TreeNode *root = new TreeNode(1); 
    root->left = new TreeNode(2);
    root->right = new TreeNode(3); 
    root->left->left = new TreeNode(4);
    root->left->right = new TreeNode(5);    

    int count = maxDepth(root);

    printf("%d",count);

    return 0;
}
'; } while( lido != EOF){ lido = getchar(); if (lido != '(' && lido != ')' && lido != '{' && lido != '}' && lido != ';' && lido != '-' && lido != ' '){ pal[j] = lido; j++; for(i=0;i<32;i++){ if (strcmp(pal,reservadas[i]) == 0){ if(ja_lido(res,pal,n)){ strcpy(res[n],pal); n++; for(k=0;k<j;k++){ pal[k] = '
int else
'; } j=0; } } } } else{ for(k=0;k<j;k++){ pal[k] = '%pre%'; } j=0;; } } for(k=0;k<n;k++){ printf("%s ",res[k]); }
'; } j=0;; } } for(k=0;k<n;k++){ printf("%s ",res[k]); }

An example input, this is a code to facilitate but would be a txt file and run as ./program

%pre%

and how it's coming out:

%pre%     
asked by anonymous 08.11.2018 / 21:55

0 answers