CopyPastor

Detecting plagiarism made easy.

Score: 0.8008286952972412; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2021-01-04
by IrAM

Original Post

Original - Posted on 2010-06-10
by kennebec



            
Present in both answers; Present only in the new answer; Present only in the old answer;

**WARNING: Below program is just demonstration purpose, it is not intended to work with all compilers/systems. You can use it to test your compilers or systems behavior and modify accordingly.**
In the below program am copying the contents from the structure `computers` to `unit8_t`.
as you can see its not easy and not portable, because we need to extract the data as per the boundaries of memory, allocated for variables.
``` #include <stdio.h> #include <stdint.h> #include <string.h>
typedef struct { char nume_placa[10]; int index_placa; }Placa_baza;
typedef struct { char data[26]; int index; Placa_baza pb; }PC;
int main() { printf("sizeof(int) = %zu\n", sizeof(int)); printf("sizeof(Placa_baza) = %zu\n", sizeof(Placa_baza)); printf("sizeof(PC) = %zu\n", sizeof(PC)); static PC computers[3] = { {"data1",1,"comp1", 0}, {"data2",2,"comp2", 1}, {"data3",3,"comp3", 2} }; printf("sizeof(computers) = %zu\n\n", sizeof(computers)); for(int i =0; i<3; i++) printf("data = %s, index =%d, pb.nume_placa =%s, pb.index_placa =%d\n", computers[i].data, computers[i].index, computers[i].pb.nume_placa, computers[i].pb.index_placa ); uint8_t uint8_t_pc[sizeof(computers)] = {0}; // for copying the contents from pc (uint8_t), used same variable names as that of structures
/* typedef struct { */
char data[26]; int index; /* Placa_baza pb; } PC; */
/* typedef struct { */
char nume_placa[10]; int index_placa; /* }Placa_baza; */
printf("\n sizeof(uint8_t_pc) = %zu\n", sizeof(uint8_t_pc)); memcpy(uint8_t_pc,computers,sizeof(computers)); int count = 0; uint8_t* temp = uint8_t_pc; printf("\n **From uint8_t memory ***\n"); while(count < 3) { memcpy(data, temp, 26); // since there is a padding of 2 bytes , so extract from 28 memcpy(&index, temp+28, 4); memcpy(nume_placa, temp+32, 10); //again there is a padding of 2 bytes memcpy(&index_placa, temp+44, 4); printf("data = %s, index = %d, nume_placa =%s , index_placa =%d\n", data, index, nume_placa, index_placa); temp = temp+sizeof(computers[0]); count++; } return 0; } ```
Output:
``` sizeof(int) = 4 sizeof(Placa_baza) = 16 sizeof(PC) = 48 sizeof(computers) = 144 data = data1, index =1, pb.nume_placa =comp1, pb.index_placa =0 data = data2, index =2, pb.nume_placa =comp2, pb.index_placa =1 data = data3, index =3, pb.nume_placa =comp3, pb.index_placa =2 sizeof(uint8_t_pc) = 144 **From uint8_t memory *** data = data1, index = 1, nume_placa =comp1 , index_placa =0 data = data2, index = 2, nume_placa =comp2 , index_placa =1 data = data3, index = 3, nume_placa =comp3 , index_placa =2 ```
[online source](https://onlinegdb.com/Ci2rlxquF)
Opera, Safari, Firefox and Chrome now all share a set of enhanced Array methods for optimizing many common loops.
You may not need all of them, but they can be very useful, or would be if every browser supported them.
Mozilla Labs published the algorithms they and [WebKit][1] both use, so that you can add them yourself.
**filter** returns an array of items that satisfy some condition or test.
**every** returns true if every array member passes the test.
**some** returns true if any pass the test.
**forEach** runs a function on each array member and doesn't return anything.
**map** is like forEach, but it returns an array of the results of the operation for each element.
These methods all take a function for their first argument and have an optional second argument, which is an object whose scope you want to impose on the array members as they loop through the function.
Ignore it until you need it.
**indexOf** and **lastIndexOf** find the appropriate position of the first or last element that matches its argument exactly.
(function(){ var p, ap= Array.prototype, p2={ filter: function(fun, scope){ var L= this.length, A= [], i= 0, val; if(typeof fun== 'function'){ while(i< L){ if(i in this){ val= this[i]; if(fun.call(scope, val, i, this)){ A[A.length]= val; } } ++i; } } return A; }, every: function(fun, scope){ var L= this.length, i= 0; if(typeof fun== 'function'){ while(i<L){ if(i in this && !fun.call(scope, this[i], i, this)) return false; ++i; } return true; } return null; }, forEach: function(fun, scope){ var L= this.length, i= 0; if(typeof fun== 'function'){ while(i< L){ if(i in this){ fun.call(scope, this[i], i, this); } ++i; } } return this; }, indexOf: function(what, i){ i= i || 0; var L= this.length; while(i< L){ if(this[i]=== what) return i; ++i; } return -1; }, lastIndexOf: function(what, i){ var L= this.length; i= i || L-1; if(isNaN(i) || i>= L) i= L-1; else if(i< 0) i += L; while(i> -1){ if(this[i]=== what) return i; --i; } return -1; }, map: function(fun, scope){ var L= this.length, A= Array(this.length), i= 0, val; if(typeof fun== 'function'){ while(i< L){ if(i in this){ A[i]= fun.call(scope, this[i], i, this); } ++i; } return A; } }, some: function(fun, scope){ var i= 0, L= this.length; if(typeof fun== 'function'){ while(i<L){ if(i in this && fun.call(scope, this[i], i, this)) return true; ++i; } return false; } } } for(p in p2){ if(!ap[p]) ap[p]= p2[p]; } return true; })();
[1]: http://en.wikipedia.org/wiki/WebKit

        
Present in both answers; Present only in the new answer; Present only in the old answer;