标签: strlen

加密解密信用卡没有

我有一些信用卡和路由号码存储在$ credit和$ routing_respectively中.在我将它插入数据库之前,我需要加密并在显示它时我需要解密它.我正在使用ZEND框架.我可以使用内置功能吗?

encryption zend-framework strlen

1
推荐指数
1
解决办法
1303
查看次数

C语言中strlen的未处理异常

我已经被困在这一段了一段时间,我不是C的专家.基本上,我试图创建一个"安全地"将角色划分到现有char*的函数.

我试图从这个例子中获得"动态分配"方法:

在C中使用strcat

我做了一些修改,我删除了由realloc函数设置的var(编译器说它返回void).我还修改它只附加一个字符而不是一个字符数组.我认为这会改变"realloc"参数,所以不是传递加法字符串的长度,而是传入"sizeof(char)"(x2,因为原来有一个额外的sizeof char,我想是因为null终止符?)

char *buffer = NULL;

int mystrcat(char addition)
{
   realloc(buffer, strlen(buffer) + sizeof(char)*2);
   if (!buffer)
     return 0;
   strcat(buffer, addition);
   return 1;
}
Run Code Online (Sandbox Code Playgroud)

我称之为:

if(!safestrcat(str[i+j]))
    printf("Out of Memory");
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我看到了这个:

myProg.exe中0x60f0d540(msvcr100d.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000000.

调试器在第81行显示strlen.asm:

main_loop:
    mov     eax,dword ptr [ecx]     ; read 4 bytes
Run Code Online (Sandbox Code Playgroud)

如果这是一个新问题,我很抱歉,但是发生了什么?为什么添加char没有附加到缓冲区?

对不起,我应该补充说,它成功编译.

c strlen

1
推荐指数
1
解决办法
2536
查看次数

Strlen返回不合理的数字

如果我写:

char  lili [3];
cout<<strlen(lili)<<endl;
Run Code Online (Sandbox Code Playgroud)

那么印刷的是:11

但如果我写:

char  lili [3];
lili [3]='\0';
cout<<strlen(lili)<<endl;
Run Code Online (Sandbox Code Playgroud)

然后我得到3.

我不明白为什么它在第一部分返回11?
strlen不应该返回3,因为我分配了3个字符lili

c++ strlen

1
推荐指数
2
解决办法
344
查看次数

在 C 中查找格式化字符串的长度

我的应用程序中有以下功能:

 void func(char *file, int line)
 {
    char stmt[150];
    sprintf(stmt, "Failed in file %s, at line number %d", file, line);
 }
Run Code Online (Sandbox Code Playgroud)

在这里,我采用 150 字节的字符数组(粗略猜测),而不是我需要找到我在 sprintf() 中给出的字符串的长度并采用该大小的数组。

请建议我是否在 C 中使用这种工具来查找格式化字符串的长度。谢谢 !

c strlen

1
推荐指数
1
解决办法
2101
查看次数

strlen()不使用字符串变量

#include <iostream>
#include <string>
#include <cstring>


using namespace std;

int main()
{
    string b="hello";

    cout<<b;

    int c = strlen(b);

    cout << "Hello world!" <<c<< endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行此操作时,我收到以下错误

||=== Build: Debug in strlen (compiler: GNU GCC Compiler) ===|
C:\Users\Waters\Desktop\hellow world\strlen\main.cpp||In function 'int main()':|
C:\Users\Waters\Desktop\hellow world\strlen\main.cpp|14|error: cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'size_t strlen(const char*)'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Run Code Online (Sandbox Code Playgroud)

c++ strlen c++11

1
推荐指数
1
解决办法
5809
查看次数

为什么我不能使用函数调用来声明数组的长度?

这就是我想要做的:

const char wav_folder[] = ".\\wav";
const char search_path[strlen(wav_folder) + 6];
Run Code Online (Sandbox Code Playgroud)

但是strlen部分不允许我创建这个字符数组.这不是编译.为什么?

错误:

Error   1   error C2057: expected constant expression   c:\users\hassan\documents\cpp\dir_search\dir_search\dir_search\source.cpp   15  1   dir_search
Error   2   error C2466: cannot allocate an array of constant size 0    c:\users\hassan\documents\cpp\dir_search\dir_search\dir_search\source.cpp   15  1   dir_search
Error   3   error C2734: 'search_path' : const object must be initialized if not extern c:\users\hassan\documents\cpp\dir_search\dir_search\dir_search\source.cpp   15  1   dir_search
Error   4   error C2133: 'search_path' : unknown size   c:\users\hassan\documents\cpp\dir_search\dir_search\dir_search\source.cpp   15  1   dir_search
Run Code Online (Sandbox Code Playgroud)

c++ arrays char strlen

1
推荐指数
1
解决办法
424
查看次数

C - strlen("288_882_288"+ strlen("288_882_288")/ 2 = 6?

所以我正在学习嵌入式系统课程,我们正在使用C.第二周,所以我们只是刷新了我们的C代码内存.

这段代码是如何打印6号的?幕后发生了什么?

int main (void) {
    char msg[] = "288_882_288";
    int my_length = 0xFFFFFFFF;
    my_length = strlen(msg+strlen(msg) /2);

    printf("%d",my_length);//prints 6
    fflush(stdout);
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

c arrays string pointers strlen

1
推荐指数
1
解决办法
137
查看次数

strlen(&string [])如何工作?

这可能是一个很长的问题。我正在用C测试一些字符数组,因此出现了这段代码。

char t[10];
strcpy(t, "abcd");
printf("%d\n", strlen(&t[5]));
printf("Length: %d\n", strlen(t));
Run Code Online (Sandbox Code Playgroud)

现在显然strlen(&t[5])strlen(t)返回4时产生3 。

我知道字符串长度为4,这从插入四个字符很明显。但是为什么strlen(&t[5])返回3?

我的猜测是

String:   a | b | c | d | 0 | 0 | 0 | 0 | 0 | \0
Position: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 
Run Code Online (Sandbox Code Playgroud)

strlen(&t[5]) 看一下由位置6、7和8组成的字符串的长度(因为第十个字符是NULL终止符,对)?

好的,然后我做了一些实验,并修改了一些代码。

char t[10];
strcpy(t, "abcdefghij");
printf("%d\n", strlen(&t[5]));
printf("Length: %d\n", strlen(t));
Run Code Online (Sandbox Code Playgroud)

现在,这一次strlen(&t[5])产生了5,而strlen(t)预期的是10。如果我正确理解字符数组,则状态现在应该为

String:   a | …
Run Code Online (Sandbox Code Playgroud)

c arrays string char strlen

1
推荐指数
1
解决办法
184
查看次数

如何最好地在C中格式化很长的字符串常量?

我有这个:

char * str = "hahahahahihihihihohohohohahahahahihihihihohohohohahahahahihihihihohohohohahahahahihihihihohohohohahahahahihihihihohohohohahahahahihihihihohohoho\0";
Run Code Online (Sandbox Code Playgroud)

我该如何正确设置其格式,以80列中断?使用方法:

char * str = "foo\
    bar";
Run Code Online (Sandbox Code Playgroud)

似乎是一个非常糟糕的主意,它导致未定义的行为,使strlen()返回的废话值

编辑:这是我正在谈论的未定义的行为:

#include <stdio.h>
#include <string.h>

int main(void)
{
    char *s = "haha\
               hihi\0";

    unsigned i = strlen(s);

    printf("Length: %i\n", i);

    return 0;
}

imperator@RomaAeterna ~/P/C/undefined> gcc -Wall -Wextra undefined.c 
imperator@RomaAeterna ~/P/C/undefined> ./a.out
Length: 14
Run Code Online (Sandbox Code Playgroud)

c string formatting strlen

1
推荐指数
1
解决办法
66
查看次数

Fail to compile: strlen is not a member of std

I'm trying to compile this very simple program where I'm implementing a simplified version of C++ strings. However the compiler cannot find the std::strlen function even though I included

//main.cpp
#include "str.h"

int main()
{
    return 0;
}

// str.h
#ifndef _STRING_H_
#define _STRING_H_

#include <vector>
#include <cstring>
#include <algorithm>
#include <iterator>

class Str {
public:
    typedef std::vector<char>::size_type size_type;

    Str() { }
    Str(size_type n, char c): data(n, c) { }
    Str(const char* cp) {
        std::copy(cp, cp+std::strlen(cp), std::back_inserter(data));
    }
    template <class …
Run Code Online (Sandbox Code Playgroud)

c++ std strlen

1
推荐指数
1
解决办法
150
查看次数

标签 统计

strlen ×10

c ×5

c++ ×4

arrays ×3

string ×3

char ×2

c++11 ×1

encryption ×1

formatting ×1

pointers ×1

std ×1

zend-framework ×1