Posts by zentrunix • 5,511 points
272 posts
-
0
votes1
answer145
viewsA: How to exchange information in full-duplex mode?
One way to do this is to create two threads (or two child processes on Unix/Linux), one thread receiving and another sending. 1 server pseudo-code that handles only 1 connection and then terminates,…
-
1
votes2
answers130
viewsA: How can I turn " to " in a bash script
A solution using the command 'tr' #!/bin/bash if [ $# -ne 2 ]; then echo "erro, precisa de 2 parametros" exit 1 fi tr '"' '\' < $1 | python > $2
-
0
votes1
answer133
viewsA: What is the effect of the bind() function on a client code?
If no bind is made in the socket used in connect then an automatic bind is made on an available port, usually a port called "ephemeral". (This also happens when you bind to port 0). In general the…
-
0
votes3
answers606
views -
1
votes1
answer407
viewsA: Read a text file and separate content into variables
Incomplete example (not holding the vertices and edges). Shows how to use the fscanf function to read fields from a text file. #include <stdio.h> #include <stdlib.h> // para exit int…
-
3
votes1
answer123
viewsA: TCP/IP protocol on Linux and Windows
Most of the communication protocols used on the Internet, including the TCP/IP suite, are defined by documents known as Request For Comments, a name always abbreviated to RFC Wikipedia. Thus, the…
-
0
votes1
answer125
viewsA: Segmentation Error
The code is very inefficient (one realloc to each character read ? wtf ?). Disregarding this, the cause of segmentation error is incorrect use of pointer. int main(int numargs, char **args) { celula…
-
1
votes2
answers141
viewsA: Comparison of string characters in C
Segmentation failure occurs because the "string2" pointer has not been initialized. #include <stdio.h> #include <stdlib.h> // para malloc e free void removerEspacosEsquerda(char…
-
-1
votes2
answers580
viewsA: How to create an optional parameter in ADVPL?
In ADVPL the parameters of a function are optional. Parameters not provided come with value nil. Example: #include "protheus.ch" user function test(xParm) if xParm != nil conout("xParm=" + xParm)…
-
-1
votes2
answers1116
viewsA: What are the scopes of the variables in the ADVPL and when to use each one?
As explained in another answer, variables private have dynamic scope. This type of scope is more common in "shell" languages, such as bash (Linux) and cmd (DOS/Windows). In general use languages it…
-
0
votes1
answer94
views -
3
votes1
answer88
viewsA: Can sockets be multilingual?
Yes. No matter in which language an application that uses sockets is written, at the end of the day communication is done by drivers at the OS level. This question doesn’t even make much sense.…
-
0
votes1
answer25
viewsA: Errors: Division by zero and iterator not dereferencable
The error of division by zero in int p = rand() % size; will occur if the variable "size" is zero. The second error is probably the result of the first error.
-
3
votes1
answer358
viewsA: Error: E0254 type name not allowed
The correct is "string::npos" and not "string.npos". In the code fragment size_t p = line.find('='); // linha 1 if (p != string::npos) // linha 2 line 1 finds the position (index) of the character…
-
0
votes1
answer71
viewsA: Makefile compile all files. c without specifying them
Reference Testing. zv@localhost test-make]$ ll total 16 -rw-rw-r--. 1 zv zv 70 nov 3 10:19 func1.c -rw-rw-r--. 1 zv zv 70 nov 3 10:20 func2.c -rw-rw-r--. 1 zv zv 277 nov 3 10:15 main.c -rw-rw-r--. 1…
-
1
votes2
answers97
viewsA: Problem in C IF checking
First of all, it doesn’t exist in C: using namespace std; Second, if "concept" is only a letter, because it is declared with 180 characters ??? char nome[180], conceito[180]; Third, the string…
-
2
votes1
answer112
viewsA: Problems comparing two Ipv6 addresses
Ipv6 addresses are usually abbreviated to eliminate long sequences of zeros. For example: 2804:d47:1b17:2100:000:0000:0000:0000 is represented by 2804:d47:1b17:2100:: You can do Ipv6 address…
-
1
votes2
answers144
viewsA: Recursive printing in triangle format
Normally I wouldn’t put a full answer, but this is an interesting exercise because of the recursion. #include <stdio.h> static void rectri(int n) { int i; if (n == 0) return; rectri(n-1); for…
-
2
votes1
answer70
viewsA: Problem with repeated number removal algorithm on doubly chained list
The aux3 pointer is being deleted twice, void removeRepetidos(Lista *l) { Elemento *aux = (*l); Elemento *aux2; Elemento *aux3; while (aux!=NULL) { aux2 = aux->prox; while (aux2 != NULL) { if…
-
1
votes1
answer226
viewsA: Problem with strcpy
In C the strings need to have a binary zero at the end. So, their structure needs to reserve space for this binary zero. Therefore its structure must be declared so: struct Aluno { char tipo; char…
-
-1
votes1
answer156
viewsA: printf being duplicated after the first loop
C data entry with scanf is a confusing subject. The use of fflush(stdin) is controversial, it doesn’t always work the way we expect. When reading a character, instead of using getchar it is more…
-
2
votes1
answer49
viewsA: Understanding Regex test on MDN
The explanation is there: Using test() on a regex with the global flag If the regex has the global flag set, test() will Advance the lastIndex of the regex. A subsequent use of test() will start the…
-
1
votes1
answer48
viewsA: What is the solution to this comparison?
To compare strings you need to use a specific function, strcmp or strncmp (preferable). TipoApontador find(TipoItem x, TipoLista* lista) { TipoApontador aux; if (lista->primeiro != NULL) { aux =…
-
3
votes1
answer1048
viewsA: Compare Strings with Struct Array in C
The way your program is written the array of structures needs to be global. ... ... struct pessoas p[5]; ... ... void consultar_registro() { // struct pessoas p[5]; // <------ int op2, i; char…
-
1
votes1
answer295
viewsA: How to convert a character to hexadecimal in Assembly
Where did this "12" ??? shr ax, 12 The right is 8 shr ax, 8 because 8 is the bit size of the AH and AL registers, and remembering, the AX register consists of the 2 AH and AL sub-registers. google:…
-
4
votes1
answer90
viewsA: Why is my server code not working with Ipv6?
You cannot use Ipv4 and Ipv6 in the same socket. In the case in question, if you want to meet Ipv6 then you need to specify the family hints.ai_family = AF_INET6; or else specify ipv6 if…
-
0
votes1
answer260
viewsA: Is it possible to send data in the body and in the url using the PUT and libcurl method?
I’ll put as an answer because the comment area is limited. First, test with Curl in the command line. If it works on the command line then it will work with lib. Second, if you are wanting to send…
-
0
votes2
answers1633
viewsA: Doubt in a simple c++ ENCRYPTION program
The problem reported happens because the type "char" is being considered as "Signed char", which is normal, but when a variable "Signed char" is converted to int the value may be negative if the…
-
1
votes1
answer41
viewsA: Copying Files using System Calls
This is wrong: while (n = read(iSource, &ch, 1) > 0) { write(iDest, &ch, 128); } you are reading 1 byte and writing 128. UPDATE: the above code is also wrong because of operator…
-
2
votes1
answer30
viewsA: Problem with macro
When you use the macro like this PRINTARRAY(vetor, LEN_VETOR); this line is replaced by while (LEN_VETOR > 0) { printf("%d",vetor[LEN_VETOR]); LEN_VETOR--; } These lines in turn are replaced by…
-
-1
votes2
answers139
viewsA: Raw socket in C
If you are an extreme high-level hacker then you can think about creating a Sniffer using raw sockets. Otherwise you can do like most people who writes sniffers and use a capture library, like the…
-
2
votes2
answers278
viewsA: No match for 'Operator==' in find C function
On the line if (aux->item == x) the expression aux->item is the type TipoItem, and the variable x is the type TipoCelula*. It is not possible to compare a Tipoitem (aux->item) structure…
-
0
votes1
answer95
viewsA: How to do arithmetic operations using directly binary in C
If you want to use the native compiler implementation (and associated libraries) then it is no use to want to outsmart the compiler: believe me, the people who wrote the compiler and the…
-
1
votes1
answer66
viewsA: Why Does My Function Bubblebest Doesn’t Rotate?
A quick visual inspection shows no problems, but as your code is a bit long (tip: see this here) and uses features specific to Windows (getch, cls), I made a minimal example that runs on Linux (and…
-
2
votes1
answer62
viewsA: Why is my C code that uses queue giving Segmentation fault?
You need to allocate memory to the queue as you are using a pointer to the queue (Queue*). There may be other errors, I didn’t test how the program works, but surely the uninitialized pointer must…
-
4
votes3
answers1572
viewsA: How to read only whole numbers in the scanf?
You need to put the #include <stdio.h> for the scanf and the printf. Also, you need to initialize the "x" variable, otherwise it will have "trash". If you type "A" and enter, the "A" you…
-
4
votes2
answers76
viewsA: Find() function of the set library does not return whether or not it found
There are 2 errors in the code. // errado cin >> valor >> valord; if (di.find(valor)) // erro de sintaxe: find retorna um "iterator" e não um bool di.insert(valor); // erro lógico: deve…
-
0
votes1
answer104
viewsA: Use a variable to limit reading of characters with fscanf and data mask
Scanf, sscanf and fscanf do not directly support variable field size specification. It is possible however to use tricks as shown here. The best solution however is to use fgets and calloc, and…
-
1
votes2
answers378
viewsA: Socket between 2 devices
In the client you need to pass the IP address or hostname of the server. Socket cliente = new Socket("0.0.0.0",12345); // <<< errado I don’t know Java, but the line above should be Socket…
-
-1
votes1
answer438
viewsA: Distributed Calculator - UDP Client/Server
You do 3 Sendto on the client, so you need to do 3 Receivefrom on the server. The operation and the 2 operands are being sent separately, each in its own UDP package.
-
1
votes3
answers238
viewsA: Error while trying to overload Operators with dates
The program shown neither compiles, because there is duplicate definition of the output operator. Also the formatting is hideous, it is not a typical formatting used with C++. Obs. numeric literals…
-
0
votes1
answer181
viewsA: SOCKETS IN C - TCP Sequence Number
Assemble the messages to be sent to the server following the requested layout, containing the sequence number and the size of the message data area. For example: message 1: 0000 0010 0123456890…
-
1
votes2
answers96
viewsA: C++: File header not recognizing class
Start here: put a semicolon after the class declaration...All class statements need a semicolon at the end. class Actor { (...) }; //<------------------------------------ Editing: Ok, since the…
-
1
votes2
answers868
viewsA: C++ Visual Studio
You need to include the "iso646.h.": #include <iso646.h> https://msdn.microsoft.com/en-us/library/c6s3h5a7.aspx…
-
0
votes1
answer116
viewsA: Meaning of this syntax
This notation std::function<bool(No*, No*, Elo*)>func indicates a pointer to a prototype function bool func(No*, No*, Elo*) which must be passed as a parameter in the function call…
-
1
votes1
answer81
viewsA: How can I pass a Descriptor file to another process?
In UNIX (and Linux) environment the process of passing a file descriptor between any processes is well known and uses the function "sendmsg" between local sockets (family AF_UNIX or AF_LOCAL). This…
-
1
votes1
answer19547
viewsA: Decimal to torque converter in C
I could not reproduce the reported error, but there is an error in the "bin" array declaration, which by its logic needs to have 8 elements. Other than that, nothing seems to be wrong. #include…
-
3
votes1
answer2985
viewsA: Std::Sort with comparison function
In C++ Std::Sort is an "algorithm", not a function. That is, Std::Sort is a generic function declared as a template. The use of the comparison function is necessary when there is no intrinsic order…
-
4
votes1
answer56
viewsA: How to create a "defnine" with undetermined arguments?
With "define" I think we can not do, but with "variadic templates" is possible, Although it is something complicated. #include <iostream> using namespace std; void adicionar(int i) { cout…
-
-1
votes2
answers167
viewsA: How to limit a function parameter so that it is an element of a set?
Surely there is more than one way to model an automaton (deterministic finite), but I think you could try something like this struct State { int id; }; using States = std::set<State>; States…