Search Results

Search found 52 results on 3 pages for 'mekasperasky'.

Page 1/3 | 1 2 3  | Next Page >

  • why am i getting error in this switch statement written in c

    - by mekasperasky
    I have a character array b which stores different identifiers in different iterations . I have to compare b with various identifiers of the programming language C and print it into a file . When i do it using the following switch statement it gives me errors b[i]='\0'; switch(b[i]) { case "if":fprintf(fp2,"if ----> IDENTIFIER \n"); case "then":fprintf(fp2,"then ----> IDENTIFIER \n"); case "else":fprintf(fp2,"else ----> IDENTIFIER \n"); case "switch":fprintf(fp2,"switch ----> IDENTIFIER \n"); case 'printf':fprintf(fp2,"prtintf ----> IDENTIFIER \n"); case 'scanf':fprintf(fp2,"else ----> IDENTIFIER \n"); case 'NULL':fprintf(fp2,"NULL ----> IDENTIFIER \n"); case 'int':fprintf(fp2,"INT ----> IDENTIFIER \n"); case 'char':fprintf(fp2,"char ----> IDENTIFIER \n"); case 'float':fprintf(fp2,"float ----> IDENTIFIER \n"); case 'long':fprintf(fp2,"long ----> IDENTIFIER \n"); case 'double':fprintf(fp2,"double ----> IDENTIFIER \n"); case 'char':fprintf(fp2,"char ----> IDENTIFIER \n"); case 'const':fprintf(fp2,"const ----> IDENTIFIER \n"); case 'continue':fprintf(fp2,"continue ----> IDENTIFIER \n"); case 'break':fprintf(fp2,"long ----> IDENTIFIER \n"); case 'for':fprintf(fp2,"long ----> IDENTIFIER \n"); case 'size of':fprintf(fp2,"size of ----> IDENTIFIER \n"); case 'register':fprintf(fp2,"register ----> IDENTIFIER \n"); case 'short':fprintf(fp2,"short ----> IDENTIFIER \n"); case 'auto':fprintf(fp2,"auto ----> IDENTIFIER \n"); case 'while':fprintf(fp2,"while ----> IDENTIFIER \n"); case 'do':fprintf(fp2,"do ----> IDENTIFIER \n"); case 'case':fprintf(fp2,"case ----> IDENTIFIER \n"); } the error being lex.c:94:13: warning: character constant too long for its type lex.c:95:13: warning: character constant too long for its type lex.c:96:13: warning: multi-character character constant lex.c:97:13: warning: multi-character character constant lex.c:98:13: warning: multi-character character constant lex.c:99:13: warning: character constant too long for its type lex.c:100:13: warning: multi-character character constant lex.c:101:13: warning: character constant too long for its type lex.c:102:13: warning: multi-character character constant lex.c:103:13: warning: character constant too long for its type lex.c:104:13: warning: character constant too long for its type lex.c:105:13: warning: character constant too long for its type lex.c:106:13: warning: multi-character character constant lex.c:107:13: warning: character constant too long for its type lex.c:108:13: warning: character constant too long for its type lex.c:109:13: warning: character constant too long for its type lex.c:110:12: warning: multi-character character constant lex.c:111:13: warning: character constant too long for its type lex.c:112:13: warning: multi-character character constant lex.c:113:13: warning: multi-character character constant lex.c: In function ‘int main()’: lex.c:90: error: case label does not reduce to an integer constant lex.c:91: error: case label does not reduce to an integer constant lex.c:92: error: case label does not reduce to an integer constant lex.c:93: error: case label does not reduce to an integer constant lex.c:94: warning: overflow in implicit constant conversion lex.c:95: warning: overflow in implicit constant conversion lex.c:95: error: duplicate case value lex.c:94: error: previously used here lex.c:96: warning: overflow in implicit constant conversion lex.c:97: warning: overflow in implicit constant conversion lex.c:98: warning: overflow in implicit constant conversion lex.c:99: warning: overflow in implicit constant conversion lex.c:99: error: duplicate case value lex.c:97: error: previously used here lex.c:100: warning: overflow in implicit constant conversion lex.c:101: warning: overflow in implicit constant conversion lex.c:102: warning: overflow in implicit constant conversion lex.c:102: error: duplicate case value lex.c:98: error: previously used here lex.c:103: warning: overflow in implicit constant conversion lex.c:103: error: duplicate case value lex.c:97: error: previously used here lex.c:104: warning: overflow in implicit constant conversion lex.c:104: error: duplicate case value lex.c:101: error: previously used here lex.c:105: warning: overflow in implicit constant conversion lex.c:106: warning: overflow in implicit constant conversion lex.c:106: error: duplicate case value lex.c:98: error: previously used here lex.c:107: warning: overflow in implicit constant conversion lex.c:107: error: duplicate case value lex.c:94: error: previously used here lex.c:108: warning: overflow in implicit constant conversion lex.c:108: error: duplicate case value lex.c:98: error: previously used here lex.c:109: warning: overflow in implicit constant conversion lex.c:109: error: duplicate case value lex.c:97: error: previously used here lex.c:110: warning: overflow in implicit constant conversion lex.c:111: warning: overflow in implicit constant conversion lex.c:111: error: duplicate case value lex.c:101: error: previously used here lex.c:112: warning: overflow in implicit constant conversion lex.c:112: error: duplicate case value lex.c:110: error: previously used here lex.c:113: warning: overflow in implicit constant conversion lex.c:113: error: duplicate case value lex.c:101: error: previously used here

    Read the article

  • error in coding a lexer in c

    - by mekasperasky
    #include<stdio.h> #include<ctype.h> #include<string.h> /* this is a lexer which recognizes constants , variables ,symbols, identifiers , functions , comments and also header files . It stores the lexemes in 3 different files . One file contains all the headers and the comments . Another file will contain all the variables , another will contain all the symbols. */ int main() { int i=0,j,k,count=0; char a,b[100],c[10000],d[100]; memset ( d, 0, 100 ); j=30; FILE *fp1,*fp2; fp1=fopen("source.txt","r"); //the source file is opened in read only mode which will passed through the lexer fp2=fopen("lext.txt","w"); //now lets remove all the white spaces and store the rest of the words in a file if(fp1==NULL) { perror("failed to open source.txt"); //return EXIT_FAILURE; } i=0; k=0; while(!feof(fp1)) { a=fgetc(fp1); if(a!=' '&&a!='\n') { if (!isalpha(a)) { switch(a) { case '+':{fprintf(fp2,"+ ----> PLUS \n"); i=0;break;} case '-':{fprintf(fp2,"- ---> MINUS \n"); i=0;break;} case '*':{fprintf(fp2, "* --->MULT \n"); i=0;break;} case '/':{fprintf(fp2, "/ --->DIV \n"); i=0;break;} //case '+=':fprintf(fp2, "%.20s\n", "ADD_ASSIGN"); //case '-=':fprintf(fp2, "%.20s\n", "SUB_ASSIGN"); case '=':{fprintf(fp2, "= ---> ASSIGN \n"); i=0;break;} case '%':{fprintf(fp2, "% ---> MOD \n"); i=0;break;} case '<':{fprintf(fp2, "< ---> LESSER_THAN \n"); i=0;break;} case '>':{fprintf(fp2, "> --> GREATER_THAN \n"); i=0;break;} //case '++':fprintf(fp2, "%.20s\n", "INCREMENT"); //case '--':fprintf(fp2, "%.20s\n", "DECREMENT"); //case '==':fprintf(fp2, "%.20s\n", "ASSIGNMENT"); case ';':{fprintf(fp2, "; --->SEMI_COLUMN \n"); i=0;break;} case ':':{fprintf(fp2, ": --->COLUMN \n"); i=0;break;} case '(':{fprintf(fp2, "( --->LPAR \n"); i=0;break;} case ')':{fprintf(fp2, ") --->RPAR \n"); i=0;break;} case '{':{fprintf(fp2, "{ --->LBRACE \n"); i=0;break;} case '}':{fprintf(fp2, "} ---> RBRACE \n"); i=0;break;} } } else { d[i]=a; //printf("%c\n",d[i]); i=i+1; } //} /* we can make the lexer more complex by including even more depths of checks for the symbols*/ } else { d[i+1]='\0'; printf("\n"); if((strcmp(d,"if ")==0)){fprintf(fp2,"if ----> IDENTIFIER \n"); //printf("%s \n",d); memset ( d, 0, 100 ); //printf("%s \n",d); count=count+1;} else if(strcmp(d,"then")==0){fprintf(fp2,"then ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"else")==0){fprintf(fp2,"else ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"switch")==0){fprintf(fp2,"switch ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"printf")==0){fprintf(fp2,"prtintf ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"scanf")==0){fprintf(fp2,"scanf ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"NULL")==0){fprintf(fp2,"NULL ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"int")==0){fprintf(fp2,"INT ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"char")==0){fprintf(fp2,"char ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"float")==0){fprintf(fp2,"float ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"long")==0){fprintf(fp2,"long ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"double")==0){fprintf(fp2,"double ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"const")==0){fprintf(fp2,"const ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"continue")==0)fprintf(fp2,"continue ----> IDENTIFIER \n"); else if(strcmp(d,"size of")==0){fprintf(fp2,"size of ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"register")==0){fprintf(fp2,"register ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"short")==0){fprintf(fp2,"short ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"auto")==0){fprintf(fp2,"auto ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"while")==0){fprintf(fp2,"while ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"do")==0){fprintf(fp2,"do ----> IDENTIFIER \n"); count=count+1;} else if(strcmp(d,"case")==0){fprintf(fp2,"case ----> IDENTIFIER \n"); count=count+1;} else if (isdigit(d[i])) { fprintf(fp2,"%s ---->NUMBER",d); } else if (isalpha(a)) { fprintf(fp2,"%s ----> Variable",d); //printf("%s",d); // memset ( d, 0, 100 );} //fprintf(fp2, "s\n", b); i=0; k=k+1; continue; } i=i+1; k=k+1; } fclose(fp1); fclose(fp2); printf("%d",count); return 0; } In this code , my source.txt has if (a+b) stored . But only ( , + and ) is getting written into lext.txt and not the identifier if or the variable a and b . Any particular reason why?

    Read the article

  • str is not callable error in python .

    - by mekasperasky
    import sys import md5 from TOSSIM import * from RadioCountMsg import * t = Tossim([]) #The Tossim object is defined here m = t.mac()#The mac layer is defined here , in which the communication takes place r = t.radio()#The radio communication link object is defined here , as the communication needs Rf frequency to transfer t.addChannel("RadioCountToLedsC", sys.stdout)# The various channels through which communication will take place t.addChannel("LedsC", sys.stdout) #The no of nodes that would be required in the simulation has to be entered here print("enter the no of nodes you want ") n=input() for i in range(0, n): m = t.getNode(i) m.bootAtTime((31 + t.ticksPerSecond() / 10) * i + 1) #The booting time is defined so that the time at which the node would be booted is given f = open("topo.txt", "r") #The topography is defined in topo.txt so that the RF frequencies of the transmission between nodes are are set lines = f.readlines() for line in lines: s = line.split() if (len(s) > 0): if (s[0] == "gain"): r.add(int(s[1]), int(s[2]), float(s[3])) #The topogrography is added to the radio object noise = open("meyer-heavy.txt", "r") #The noise model is defined for the nodes lines = noise.readlines() for line in lines: str = line.strip() if (str != ""): val = int(str) for i in range(0, 4): t.getNode(i).addNoiseTraceReading(val) for i in range (0, n): t.getNode(i).createNoiseModel() #The noise model is created for each node for i in range(0,n): t.runNextEvent() fk=open("key.txt","w") for i in range(0,n): if i ==0 : key=raw_input() fk.write(key) ak=key key=md5.new() key.update(str(ak)) ak=key.digest() fk.write(ak) fk.close() fk=open("key.txt","w") plaint=open("pt.txt") for i in range(0,n): msg = RadioCountMsg() msg.set_counter(7) pkt = t.newPacket()#A packet is defined according to a certain format print("enter message to be transported") ms=raw_input()#The message to be transported is taken as input #The RC5 encryption has to be done here plaint.write(ms) pkt.setData(msg.data) pkt.setType(msg.get_amType()) pkt.setDestination(i+1)#The destination to which the packet will be sent is set print "Delivering " + " to" ,i+1 pkt.deliver(i+1, t.time() + 3) fk.close() print "the key to be displayed" ki=raw_input() fk=open("key.txt") for i in range(0,n): if i==ki: ms=fk.readline() for i in range(0,n): msg=RadioCountMsg() msg.set_counter(7) pkt=t.newPacket() msg.data=ms pkt.setData(msg.data) pkt.setType(msg.get_amType()) pkt.setDestination(i+1) pkt.deliver(i+1,t.time()+3) #The key has to be broadcasted here so that the decryption can take place for i in range(0, n): t.runNextEvent(); this code gives me error here key.update(str(ak)) . when i run a similar code on the python terminal there is no such error but this code pops up an error . why so?

    Read the article

  • ./a.out termniated . Garbage output due to smashing of stack . How to remove this error ?

    - by mekasperasky
    #include <iostream> #include <fstream> #include <cstring> using namespace std; typedef unsigned long int WORD; /* Should be 32-bit = 4 bytes */ #define w 32 /* word size in bits */ #define r 12 /* number of rounds */ #define b 16 /* number of bytes in key */ #define c 4 /* number words in key */ /* c = max(1,ceil(8*b/w)) */ #define t 26 /* size of table S = 2*(r+1) words */ WORD S [t],L[c]; /* expanded key table */ WORD P = 0xb7e15163, Q = 0x9e3779b9; /* magic constants */ /* Rotation operators. x must be unsigned, to get logical right shift*/ #define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1))))) #define ROTR(x,y) (((x)>>(y&(w-1))) | ((x)<<(w-(y&(w-1))))) void RC5_ENCRYPT(WORD *pt, WORD *ct) /* 2 WORD input pt/output ct */ { WORD i, A=pt[0]+S[0], B=pt[1]+S[1]; for (i=1; i<=r; i++) { A = ROTL(A^B,B)+S[2*i]; B = ROTL(B^A,A)+S[2*i+1]; } ct [0] = A ; ct [1] = B ; } void RC5_DECRYPT(WORD *ct, WORD *pt) /* 2 WORD input ct/output pt */ { WORD i, B=ct[1], A=ct[ 0]; for (i=r; i>0; i--) { B = ROTR(B-S [2*i+1],A)^A; A = ROTR(A-S [2*i],B)^B; } pt [1] = B-S [1] ;pt [0] = A-S [0]; } void RC5_SETUP(unsigned char *K) /* secret input key K 0...b-1] */ { WORD i, j, k, u=w/8, A, B, L [c]; /* Initialize L, then S, then mix key into S */ for (i=b-1,L[c-1]=0; i!=-1; i--) L[i/u] = (L[i/u]<<8)+K[ i]; for (S [0]=P,i=1; i<t; i++) S [i] = S [i-1]+Q; for (A=B=i=j=k=0; k<3*t; k++,i=(i+1)%t,j=(j+1)%c) /* 3*t > 3*c */ { A = S[i] = ROTL(S [i]+(A+B),3); B = L[j] = ROTL(L[j]+(A+B),(A+B)); } } void printword(WORD A) { WORD k; for (k=0 ;k<w; k+=8) printf("%c"); } int main() { WORD i, j, k,ptext, pt1 [2], pt2 [2], ct [2] = {0,0}; ifstream in("key1.txt"); ifstream in1("plt.txt"); ofstream out1("cpt.txt"); if(!in) { cout << "Cannot open file.\n"; return 1; } if(!in1) { cout << "Cannot open file.\n"; return 1; } unsigned char key[b]; in >> key; in1 >> pt1[0]; in1 >> pt1[0]; if (sizeof(WORD)!=4) printf("RC5 error: WORD has %d bytes.\n",sizeof(WORD)); RC5_SETUP(key); RC5_ENCRYPT(pt1,ct); printf("\n plaintext "); printword(pt1 [0]); printword(pt1 [1]); printf(" ---> ciphertext "); printword(ct [0]); printword(ct [1]); printf("\n"); RC5_SETUP(key); RC5_DECRYPT(ct,pt2); out1<<ct[0]; out1<<ct[1]; out1 <<"\n"; printf("\n plaintext "); printword(pt1 [0]); printword(pt1 [1]); return 0; } Let the plt.txt file contain 101 100 let the key be 111

    Read the article

  • python lists error

    - by mekasperasky
    #defining the magic constants p=0xb7e15163 q=0x9e3779b9 pt=list() pt1=list() ct=list() pt2=list() #pt[0]=0pt1[0]=ct[0]=pt1[1]=ct[1]=0 s=[] l=[] b=8 key=[0,0,0,0,0,0,0,0,0] w=8 t=16 def enc(c,d): for i in range(1,r): A=A+s[0] B=B+s[1] A=A^B A=str(A) B=str(B) A=A[len(B):]+A[:len(B)] B=B^A A=str(A) B=str(B) B=B[len(A):]+B[:len(B)] A=A+s[2*i] B=B+s[2*i+1] ct.append(A) ct.append(B) def denc(): for i in range(r,1): A=ct[0] B=ct[1] B=B-s[2*i+1] B=B[len(c):] + B[:len(c)] B=B^A A=A-s[2*i] A=A[:len(B)]+c[len(B):] A=A^B pt1[1]=B-S[1] pt1[0]=A-S[0] def setup(k): u=w/8 for i in range(b-1,0): l.append(l[i/u:8]+l[8:i/u]+k[i]) s.append(p) for i in range(1,t-1): s.append(s[i-1] + q) i=j=0 A=B=0 for i in range(0,3*t): A=s.append(s[i]+A+B) B=s.append(s[:3]+s[3:]) #B=l.append((l[j]+A+B)) ll=len(str(A))+len(str(B)) B=l.append(l[:ll]+l[ll:]) i=(i+1)%t j=(j+1)%t def pri(g): for k in range(0,w): print g & 0xFF #for i in range(0,b): #key[i]=ct[0]%(255-j) pt1=[raw_input()] pt1=[raw_input()] setup(key) enc(pt1,ct) denc(ct,pt2) print("key") print(key) print("plaintext") printword(pt1[0]),printword(pt1[1]) printword(ct[0]),printword(ct[1]) the list l is always going out of index though it should not . I am not able to take the length of the string A even though it is a string .Once i convert it to string i am not able to add it in s[j]+A+B. How to get around such errors and make the code more hygenic .. This is an rc5 cipher.

    Read the article

  • assigning a list in python

    - by mekasperasky
    pt=[2] pt[0]=raw_input() when i do this , and give an input suppose 1011 , it says list indexing error- " list assignment index out of range" . may i know why? i think i am not able to assign a list properly . how to assign an array of 2 elements in python then?

    Read the article

  • error in a pygame code

    - by mekasperasky
    # INTIALISATION import pygame, math, sys from pygame.locals import * screen = pygame.display.set_mode((1024, 768)) car = pygame.image.load('car.png') clock = pygame.time.Clock() k_up = k_down = k_left = k_right = 0 speed = direction = 0 position = (100, 100) TURN_SPEED = 5 ACCELERATION = 2 MAX_FORWARD_SPEED = 10 MAX_REVERSE_SPEED = ­5 BLACK = (0,0,0) while 1: # USER INPUT clock.tick(30) for event in pygame.event.get(): if not hasattr(event, 'key'): continue down = event.type == KEYDOWN # key down or up? if event.key == K_RIGHT: k_right = down * ­5 elif event.key == K_LEFT: k_left = down * 5 elif event.key == K_UP: k_up = down * 2 elif event.key == K_DOWN: k_down = down * ­2 elif event.key == K_ESCAPE: sys.exit(0) # quit the game screen.fill(BLACK) # SIMULATION # .. new speed and direction based on acceleration and turn speed += (k_up + k_down) if speed > MAX_FORWARD_SPEED: speed = MAX_FORWARD_SPEED if speed < MAX_REVERSE_SPEED: speed = MAX_REVERSE_SPEED direction += (k_right + k_left) # .. new position based on current position, speed and direction x, y = position rad = direction * math.pi / 180 x += ­speed*math.sin(rad) y += ­speed*math.cos(rad) position = (x, y) # RENDERING # .. rotate the car image for direction rotated = pygame.transform.rotate(car, direction) # .. position the car on screen rect = rotated.get_rect() rect.center = position # .. render the car to screen screen.blit(rotated, rect) pygame.display.flip() enter code here the error i get is this Non-ASCII character '\xc2' in file race1.py on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Not able to understand what the error is and how to get rid of it?

    Read the article

  • Error while trying to parse a website url using python . how to debug it ?

    - by mekasperasky
    #!/usr/bin/python import json import urllib from BeautifulSoup import BeautifulSoup from BeautifulSoup import BeautifulStoneSoup import BeautifulSoup def showsome(searchfor): query = urllib.urlencode({'q': searchfor}) url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query search_response = urllib.urlopen(url) search_results = search_response.read() results = json.loads(search_results) data = results['responseData'] print 'Total results: %s' % data['cursor']['estimatedResultCount'] hits = data['results'] print 'Top %d hits:' % len(hits) for h in hits: print ' ', h['url'] resp = urllib.urlopen(h['url']) res = resp.read() soup = BeautifulSoup(res) print soup.prettify() print 'For more results, see %s' % data['cursor']['moreResultsUrl'] showsome('sachin') What is the wrong in this code ? Note all the 4 links that I am getting out of the search , I am feeding it back to extract the contents out of it , and then use BeautifulSoup to parse it . How should I go about it ?

    Read the article

  • error in finding out the lexems and no of lines of a text file in C

    - by mekasperasky
    #include<stdio.h> #include<ctype.h> #include<string.h> int main() { int i=0,j,k,lines_count[2]={1,1},operand_count[2]={0},operator_count[2]={0},uoperator_count[2]={0},control_count[2]={0,0},cl[13]={0},variable_dec[2]={0,0},l,p[2]={0},ct,variable_used[2]={0,0},constant_count[2],s[2]={0},t[2]={0}; char a,b[100],c[100]; char d[100]={0}; j=30; FILE *fp1[2],*fp2; fp1[0]=fopen("program1.txt","r"); fp1[1]=fopen("program2.txt","r"); //the source file is opened in read only mode which will passed through the lexer fp2=fopen("ccv1ouput.txt","wb"); //now lets remove all the white spaces and store the rest of the words in a file if(fp1[0]==NULL) { perror("failed to open program1.txt"); //return EXIT_FAILURE; } if(fp1[1]==NULL) { perror("failed to open program2.txt"); //return EXIT_FAILURE; } i=0; k=0; ct=0; while(ct!=2) { while(!feof(fp1[ct])) { a=fgetc(fp1[ct]); if(a!=' '&&a!='\n') { if (!isalpha(a) && !isdigit(a)) { switch(a) { case '+':{ i=0; cl[0]=1; operator_count[ct]=operator_count[ct]+1;break;} case '-':{ cl[1]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '*':{ cl[2]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '/':{ cl[3]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '=':{a=fgetc(fp1[ct]); if (a=='='){cl[4]=1; operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1;} else { cl[5]=1; operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1; ungetc(1,fp1[ct]); } break;} case '%':{ cl[6]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '<':{ a=fgetc(fp1[ct]); if (a=='=') {cl[7]=1; operator_count[ct]=operator_count[ct]+1;} else { cl[8]=1; operator_count[ct]=operator_count[ct]+1; ungetc(1,fp1[ct]); } break; } case '>':{ ; a=fgetc(fp1[ct]); if (a=='='){cl[9]=1; operator_count[ct]=operator_count[ct]+1;} else { cl[10]=1; operator_count[ct]=operator_count[ct]+1; ungetc(1,fp1[ct]); } break;} case '&':{ cl[11]=1; a=fgetc(fp1[ct]); operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1; variable_used[ct]=variable_used[ct]-1; break; } case '|':{ cl[12]=1; a=fgetc(fp1[ct]); operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1; variable_used[ct]=variable_used[ct]-1; break; } case '#':{ while(a!='\n') { a=fgetc(fp1[ct]); } } } } else { d[i]=a; i=i+1; k=k+1; } } else { //printf("%s \n",d); if((strcmp(d,"if")==0)){ memset ( d, 0, 100 ); i=0; control_count[ct]=control_count[ct]+1; } else if(strcmp(d,"then")==0){ i=0;memset ( d, 0, 100 );control_count[ct]=control_count[ct]+1;} else if(strcmp(d,"else")==0){ i=0;memset ( d, 0, 100 );control_count[ct]=control_count[ct]+1;} else if(strcmp(d,"while")==0){ i=0;memset ( d, 0, 100 );control_count[ct]=control_count[ct]+1;} else if(strcmp(d,"int")==0){ while(a != '\n') { a=fgetc(fp1[ct]); if (isalpha(a) ) variable_dec[ct]=variable_dec[ct]+1; } memset ( d, 0, 100 ); lines_count[ct]=lines_count[ct]+1; } else if(strcmp(d,"char")==0){while(a != '\n') { a=fgetc(fp1[ct]); if (isalpha(a) ) variable_dec[ct]=variable_dec[ct]+1; } memset ( d, 0, 100 ); lines_count[ct]=lines_count[ct]+1; } else if(strcmp(d,"float")==0){while(a != '\n') { a=fgetc(fp1[ct]); if (isalpha(a) ) variable_dec[ct]=variable_dec[ct]+1; } memset ( d, 0, 100 ); lines_count[ct]=lines_count[ct]+1; } else if(strcmp(d,"printf")==0){while(a!='\n') a=fgetc(fp1[ct]); memset(d,0,100); } else if(strcmp(d,"scanf")==0){while(a!='\n') a=fgetc(fp1[ct]); memset(d,0,100);} else if (isdigit(d[i-1])) { memset ( d, 0, 100 ); i=0; constant_count[ct]=constant_count[ct]+1; operand_count[ct]=operand_count[ct]+1; } else if (isalpha(d[i-1]) && strcmp(d,"int")!=0 && strcmp(d,"char")!=0 && strcmp(d,"float")!=0 && (strcmp(d,"if")!=0) && strcmp(d,"then")!=0 && strcmp(d,"else")!=0 && strcmp(d,"while")!=0 && strcmp(d,"printf")!=0 && strcmp(d,"scanf")!=0) { memset ( d, 0, 100 ); i=0; operand_count[ct]=operand_count[ct]+1; } else if(a=='\n') { lines_count[ct]=lines_count[ct]+1; memset ( d, 0, 100 ); } } } fclose(fp1[ct]); operand_count[ct]=operand_count[ct]-5; variable_used[0]=operand_count[0]-constant_count[0]; variable_used[1]=operand_count[1]-constant_count[1]; for(j=0;j<12;j++) uoperator_count[ct]=uoperator_count[ct]+cl[j]; fprintf(fp2,"\n statistics of program %d",ct+1); fprintf(fp2,"\n the no of lines ---> %d",lines_count[ct]); fprintf(fp2,"\n the no of operands --->%d",operand_count[ct]); fprintf(fp2,"\n the no of operator --->%d",operator_count[ct]); fprintf(fp2,"\n the no of control statments --->%d",control_count[ct]); fprintf(fp2,"\n the no of unique operators --->%d",uoperator_count[ct]); fprintf(fp2,"\n the no of variables declared--->%d",variable_dec[ct]); fprintf(fp2,"\n the no of variables used--->%d",variable_used[ct]); fprintf(fp2,"\n ---------------------------------"); fprintf(fp2,"\n \t \t \t"); ct=ct+1; } t[0]=lines_count[0]+control_count[0]+uoperator_count[0]; t[1]=lines_count[1]+control_count[1]+uoperator_count[1]; s[0]=operator_count[0]+operand_count[0]+variable_dec[0]+variable_used[0]; s[1]=operator_count[1]+operand_count[1]+variable_dec[1]+variable_used[1]; fprintf(fp2,"\n the time complexity of program 1 is %d",t[0]); fprintf(fp2,"\n the time complexity of program 2 is %d",t[1]); fprintf(fp2,"\n the space complexity of program 1 is %d",s[0]); fprintf(fp2,"\n the space complexity of program 2 is %d",s[1]); if((t[0]>t[1]) && (s[0] >s[1])) fprintf(fp2,"\n the efficiency of program 2 is greater than program 1"); else if(t[0]<t[1] && s[0] < s[1]) fprintf(fp2,"\n the efficiency of program 1 is greater than program 2 " ); else if (t[0]+s[0] > t[1]+s[1]) fprintf(fp2,"\n the efficiency of program 1 is greater than program 2"); else if (t[0]+s[0] < t[1]+s[1]) fprintf(fp2,"\n the efficiency of program 2 is greater than program 1"); else if (t[0]+s[0] == t[1]+s[1]) fprintf(fp2,"\n the efficiency of program 1 is equal to that of program 2"); fclose(fp2); return 0; } this code basically compares two c codes and finds out the no. of variables declared , used , no. of control statements , no. of lines and no. of unique operators , and operands , so as to find out the time complexity and space complexity of of the two programs given in the text file program1.txt and program2.txt ... Lets say program1.txt is this #include<stdio.h> #include<math.h> int main () { FILE *fp; fp=fopen("output.txt","w"); long double t,y=0,x=0,e=5,f=1,w=1; for (t=0;t<10;t=t+0.01) { //if (isnan(y) || isinf(y)) //break; fprintf(fp,"%ld\t%ld\n",y,x); y = y + ((e*(1 - (x*x))*y) - x + f*cos(w*0.1))*0.1; x = x + y*0.1; } fclose(fp); return (0); } i havent indented it as its just a text file . But my output is totally faulty . Its not able to find the any of the ouput that i need . Where is the bug in this ? I am not able to figure out as the algorithm looks fine .

    Read the article

  • what does this error mean in c?

    - by mekasperasky
    #include<stdio.h> #include<ctype.h> int main() { char a,b; FILE *fp; fp=fopen("lext.txt","w"); fprintf(fp,"PLUS"); return 0; } the error i get is this /tmp/ccQyyhxo.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status

    Read the article

  • segmentation fault in file operations in c

    - by mekasperasky
    #include<stdio.h> /* this is a lexer which recognizes constants , variables ,symbols, identifiers , functions , comments and also header files . It stores the lexemes in 3 different files . One file contains all the headers and the comments . Another file will contain all the variables , another will contain all the symbols. */ int main() { int i; char a,b[20],c; FILE *fp1; fp1=fopen("source.txt","r"); //the source file is opened in read only mode which will passed through the lexer //now lets remove all the white spaces and store the rest of the words in a file if(fp1==NULL) { perror("failed to open source.txt"); //return EXIT_FAILURE; } i=0; while(1) { a=fgetc(fp1); if(a !="") { b[i]=a; } else { fprintf(fp1, "%.20s\n", b); i=0; continue; } i=i+1; /*Switch(a) { case EOF :return eof; case '+':sym=sym+1; case '-':sym=sym+1; case '*':sym=sym+1; case '/':sym=sym+1; case '%':sym=sym+1; case ' */ } return 0; } how does this code end up in segmentation fault?

    Read the article

  • error in coding in pygame.

    - by mekasperasky
    import pygame from pygame.locals import * screen=pygame.display.set_mode() nin=pygame.image.load('/home/satyajit/Desktop/nincompoop0001.bmp') screen.blit(nin,(50,100)) according to the code i should get a screen with an image of nin on it . But I only get a black screen which doesnt go even though i press the exit button on it. how to get the image on the screen?

    Read the article

  • A python code to convert a number from any base to the base of 10 giving errors . What is wrong with this code?

    - by mekasperasky
    import math def baseencode(number, base): ##Converting a number of any base to base10 if number == 0: return '0' for i in range(0,len(number)): if number[i]!= [A-Z]: num = num + number[i]*pow(i,base) else : num = num + (9 + ord(number[i])) *pow(i,base) return num a = baseencode('20',5) print a Errors I get are Traceback (most recent call last): File "doubtrob.py", line 19, in <module> a = baseencode('20',5) File "doubtrob.py", line 13, in baseencode if number[i]!= [A-Z]: NameError: global name 'A' is not defined

    Read the article

1 2 3  | Next Page >