-
Conteúdo Similar
-
Por Sharank
Strcat Function In C++
I'm new to C and C++ programming, can anyone give me a hint on what I'm doing wrong here. I'm trying to write to concat function that takes to pointers to chars and concatenates the second to the first. The code does do that, but the problem is that it adds a bunch of junk at the end.
For instance, when passing the arguments - "green" and "blue", the output will be "greenblue" plus a bunch of random characters. I also wrote the strlen function that strcat uses, which I will provide below it for reference. I'm using the online compiler at InterviewBit The exact instructions and specification is this:
int main(int argc, char** argv)
{
const int MAX = 100;
char s1[MAX];
char s2[MAX];
cout << "Enter your first string up to 99 characters. ";
cin.getline(s1, sizeof(s1));
int size_s1 = strlen(s1);
cout << "Length of first string is " << size_s1 << "\n";
cout << "Enter your second string up to 99 characters. ";
cin.getline(s2, sizeof(s2));
int size_s2 = strlen(s2);
cout << "Length of second string is " << size_s2 << "\n";
cout << " Now the first string will be concatenated with the second
string ";
char* a = strcat(s1,s2);
for(int i = 0; i<MAX; i++)
cout <<a;
// system("pause");
return 0;
}
//strcat function to contatenate two strings
char* strcat(char *__s1, const char *__s2)
{
int indexOfs1 = strlen(__s1);
int s2L = strlen(__s2);
cout <<s2L << "\n";
int indexOfs2 = 0;
do{
__s1[indexOfs1] = __s2[indexOfs2];
indexOfs1++;
indexOfs2++;
}while(indexOfs2 < s2L);
return __s1;
}
//Returns length of char array
size_t strlen(const char *__s)
{
int count = 0;
int i;
for (i = 0; __s != '\0'; i++)
count++;
return (count) / sizeof(__s[0]);
}
-
Por roberson abalaid
#include <stdio.h>
#include <stdlib.h>
int arr[3][5];
int main(){
printf("Favor inserir os dados...\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
scanf("%d", &arr[j]);
}
}
printf("os valores inseridos foram...\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
printf(" %d ", arr[j]);
}
printf("\n");
}
return 0;
}
-
Por Fernando Rafael
Boa tarde, estou com um problema ao tentar usar o CMD para imprimir o conteúdo de um arquivo TXT, estou usando o comando:
PRINT /d:"\\cxgeral\Brother HL-1210W series" "imprimir.txt"
A impressora responde e faz o processo de impressão, porém a página sai em branco, usando este mesmo comando em uma impressora de pedido (Daruma DR800, Epson T20X, Elgin i9) funciona normalmente. mas em uma impressora comum fica em branco, sei que as impressoras na qual deram certo permitem impressão escrevendo direto na porta na qual estão instaladas. Mas a minha "Brother Hl-1210W" é uma impressora laser A4.
Agradeço pela atenção.
visite: www.sisnorg.com
-
Por janir.matheus
Bom dia, não tenho muita prática com JavaScript (tive contato apenas durante um período no CEDERJ). Ocorre que agora preciso do bendito, e não estou conseguindo sair de uma situação. Vou postar o código:
<script language="JavaScript"> coordenadas = ""; //Defini essa variável segundo meus conhecimentos, por ter omitido a palavra 'var' ela é global function sucesso(posicao) { coordenadas = posicao.coords.latitude; //document.write(coordenadas); //Aqui dentro ela escreve o valor da latitude } if('geolocation' in navigator) { navigator.geolocation.getCurrentPosition(sucesso); } else { alert("Navegador incompatível com esse recurso"); } document.write(coordenadas); //Aqui eu NÃO consigo pegar o valor </script> Basicamente eu quero salvar os valores de Latitude, Longitude e Timestamp em variáveis para poder usa-las posteriormente. Conto com a vossa ajuda.
Obrigado.
-
Por mr22robot
Boa tarde.
Oque eu preciso: Retornar registros sem repetir os que começam com os mesmo nomes.
Ex:
em uma tabela eu tenho:
Rafael Vieira
Rafael Martins
Lucia Vieira
Deve retornar:
Rafael Vieira
Lucia Vieira.
Neste caso eu faria para comparar as 5 primeiras letras. pra mim já serve. Pq o que eu preciso é:
Comparar os 8 primeiro digitos de CNPJ em uma tabela e ignorar os que começam iguais.
Alguem consegue me ajudar?
Muito grato
-