Sponsored Content
Full Discussion: How can I do that ?
Top Forums Programming How can I do that ? Post 302095218 by !_30 on Sunday 5th of November 2006 04:35:37 AM
Old 11-05-2006
Hey , dude , I try that code out .. but this is not what I wanted.I wanted string a to be totaly replaced with string b without those 2 pluses.

Let's take an example , on your code :

Code:
#include <stdio.h>
#include <string.h>
main()
{
        char a[]="not working";
        char b[]="cool++";
        printf("a = %s \n", a);
        strncpy(a,b,strlen(b)-2);
        printf("a = %s \n", a);
        printf("b = %s \n",b);
        exit(0);
}

result :
a = not working
a = coolworking
b = cool++

The thing is , that I wanted , a become a="cool" , not a become "coolworking" .. totaly replace.In my first example strlen(!_30)==strlen(cool) .. my bad ..

Smilie

P.S. : I hate C , on string processing .. Smilie


I made something , like , and it's working like I want ( maybe some users need this idea ).

Code:

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

int
main()
{

char a[]="now is working";
char b[]="cool++";
char bug[256];
int g;

printf("a = %s \n",a);

        for (g=0;g<strlen(b)-2;g++)
                      { bug[g]=b[g]; }
                       bug[g]='\0';
        stpcpy(a,bug);
        printf("a = %s \n",a);
exit(0);


        }

Result :

a="now is working"
a="cool".

Smilie

Last edited by !_30; 11-05-2006 at 06:17 AM..
 
STRING(3)						     Linux Programmer's Manual							 STRING(3)

NAME
stpcpy, strcasecmp, strcat, strchr, strcmp, strcoll, strcpy, strcspn, strdup, strfry, strlen, strncat, strncmp, strncpy, strncasecmp, strp- brk, strrchr, strsep, strspn, strstr, strtok, strxfrm, index, rindex - string operations SYNOPSIS
#include <strings.h> int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t n); char *index(const char *s, int c); char *rindex(const char *s, int c); #include <string.h> char *stpcpy(char *dest, const char *src); char *strcat(char *dest, const char *src); char *strchr(const char *s, int c); int strcmp(const char *s1, const char *s2); int strcoll(const char *s1, const char *s2); char *strcpy(char *dest, const char *src); size_t strcspn(const char *s, const char *reject); char *strdup(const char *s); char *strfry(char *string); size_t strlen(const char *s); char *strncat(char *dest, const char *src, size_t n); int strncmp(const char *s1, const char *s2, size_t n); char *strncpy(char *dest, const char *src, size_t n); char *strpbrk(const char *s, const char *accept); char *strrchr(const char *s, int c); char *strsep(char **stringp, const char *delim); size_t strspn(const char *s, const char *accept); char *strstr(const char *haystack, const char *needle); char *strtok(char *s, const char *delim); size_t strxfrm(char *dest, const char *src, size_t n); DESCRIPTION
The string functions perform string operations on null-terminated strings. See the individual man pages for descriptions of each function. SEE ALSO
index(3), rindex(3), stpcpy(3), strcasecmp(3), strcat(3), strchr(3), strcmp(3), strcoll(3), strcpy(3), strcspn(3), strdup(3), strfry(3), strlen(3), strncasecmp(3), strncat(3), strncmp(3), strncpy(3), strpbrk(3), strrchr(3), strsep(3), strspn(3), strstr(3), strtok(3), strxfrm(3) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2010-02-25 STRING(3)
All times are GMT -4. The time now is 12:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy