logo
down
shadow

Need to make a function to code a word


Need to make a function to code a word

By : Small Ding
Date : November 17 2020, 04:28 AM
will be helpful for those in need Your program can be greatly simplified. The logic for the "encode" logic should be just a couple lines of code. Your function declaration/prototype is also exceedingly complicated. Don't forget that a C-string is just a character array terminated with the NULL character ('\0').
Code Listing
code :
/*******************************************************************************
 * Preprocessor directives
 ******************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>


/*******************************************************************************
 * Constants
 ******************************************************************************/
#define MAX_BUF_SIZE

/*******************************************************************************
 * Function Prototypes
 ******************************************************************************/
void encode(char* str, size_t length);


/*******************************************************************************
 * Function Definitions
 ******************************************************************************/
void encode(char* str, size_t length) {
   if (!str || (length <= 1)) {
      return;
   }
   int i;
   for (i=0; i<length; i++) {
      if (isalpha(str[i])) {
         if (isupper(str[i])) {
            str[i] = 'Z' - str[i] + 'A';
         } else {
            str[i] = 'z' - str[i] + 'a';
         }
      }
   }
}

int main(void) {
   char buf1[] = "This is a test";
   char buf2[] = "abcdefghijklmnopqrstuvwxyz";
   char buf3[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   char* inputStrings[] = {buf1, buf2, buf3};
   char* buf;
   int i;

   for (i=0; i<3; i++) {
      buf = inputStrings[i];
      printf("Original String: %s\n", buf);
      encode(buf, strlen(buf));
      printf("Encoded String:  %s\n", buf);
      encode(buf, strlen(buf));
      printf("Decoded String:  %s\n", buf);
   }

   return 0;
}
Original String: This is a test
Encoded String:  Gsrh rh z gvhg
Decoded String:  This is a test
Original String: abcdefghijklmnopqrstuvwxyz
Encoded String:  zyxwvutsrqponmlkjihgfedcba
Decoded String:  abcdefghijklmnopqrstuvwxyz
Original String: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Encoded String:  ZYXWVUTSRQPONMLKJIHGFEDCBA
Decoded String:  ABCDEFGHIJKLMNOPQRSTUVWXYZ


Share : facebook icon twitter icon
How to make forward-word, backward-word, treat underscore as part of a word?

How to make forward-word, backward-word, treat underscore as part of a word?


By : Rainer
Date : March 29 2020, 07:55 AM
Any of those help As huaiyuan mentioned, you ned to modify your syntax table. That said, what he posted modifies the current table...
Each language has a syntax table, e.g. For c++, you could do
how to make 1st letter of each word capital using c# code

how to make 1st letter of each word capital using c# code


By : Omid jaan Mashar
Date : March 29 2020, 07:55 AM
will help you What you're describing is sometimes called ProperCase, or in C# case, TitleCase. It might seem like overkill, but as far as I know it takes some 'cultural' localization information. Luckily you can just default to the one currently in use.
code :
CultureInfo c   = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = c.TextInfo;

String newString = textInfo.ToTitleCase(oldString);
How do I make an OnClick function that will change a word when a user clicks it to another word?

How do I make an OnClick function that will change a word when a user clicks it to another word?


By : 野比のび太
Date : March 29 2020, 07:55 AM
help you fix your problem Okay so, I want to make an OnClick function in JavaScript that makes it so when a user clicks on it, it will change the word. Is there a replaceword() function or something that which will let me do so? I know this is not real code, but for example: , No, there isn't any native function, but you can create on your own.
code :
function replaceword(that, word, oword) {
    that.textContent = that.textContent == oword ? word : oword;
}
<p>Quickly<span onclick="replaceword(this,'Surf','Search');">Search</span>The Web!</p>
How to make a VBA word code run faster?

How to make a VBA word code run faster?


By : user5512944
Date : March 29 2020, 07:55 AM
wish helps you The comments are all correct here, you only need to run the find and replace once per item in your list, you are running it multiple times by the amount of words in the document.
code :
Option Explicit

Sub HighlightMultipleWords()
Dim AryWords(2) As String
Dim VntStore    As Variant

'Define list.
'If you add or delete, change value above in Dim statement.
AryWords(0) = "word1"
AryWords(1) = "word2"
AryWords(2) = "word3"

'Set highlight color.
Options.DefaultHighlightColorIndex = wdYellow
With Selection.Find
    'Clear existing formatting and settings in Find feature.
    .ClearFormatting
    .Replacement.ClearFormatting

    'Set highlight to replace setting.
    Selection.Find.Replacement.Highlight = True

    'Process the array
    For Each VntStore In AryWords
        .Execute FindText:=VntStore, _
                 MatchCase:=False, _
                 MatchWholeWord:=False, _
                 MatchWildcards:=False, _
                 MatchSoundsLike:=False, _
                 MatchAllWordForms:=False, _
                 Forward:=True, _
                 Wrap:=wdFindContinue, _
                 Format:=True, _
                 Replace:=wdReplaceAll
    Next
End With

End Sub
Optimized alternative code for the function to reverse input string word by word in SQL SERVER

Optimized alternative code for the function to reverse input string word by word in SQL SERVER


By : Andreas
Date : March 29 2020, 07:55 AM
around this issue T-SQL is not best solution for string manipulation. But it could be done without loop at all (SQL Server 2017+):
code :
DECLARE @s NVARCHAR(MAX) = N'My name is Jarvis';

SELECT @s, STRING_AGG(value, ' ') WITHIN GROUP(ORDER BY rn DESC)
FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY 1/0)AS rn
      FROM STRING_SPLIT(REPLACE(@s, ' ', '.'), '.'))s;
Related Posts Related Posts :
  • C - Get pointer adress to string
  • how to start a function using a Struct?
  • Trying to tweak sscanf() to ignore \n and \t
  • How to find the inverse of a Rectangular Matrix in C using GSL
  • sizeof() showing different output
  • How to select/read/copy values after specific character in a string
  • Jump from bootloader generates exception
  • Array dropping values, picks up garbage
  • Swig: Syntax error in input(3)
  • multiple definition and making sure function is correctly written
  • MD4 openssl core dumped
  • Undefined-Behavior at its best, is it -boundary break? -bad pointer arithmetic? Or just -ignore of aliasing?
  • Why am i getting problem3.c:20:23: error: expected expression before ‘int’?
  • Right Justified Zero filled String in C
  • C Function with parameter without type indicator still works?
  • How to transmit data from an interrupt handler to an user application?
  • Why do I get the error "bash: ./a.out: Permission denied" when I execute a C program in Linux mint 15
  • syntax of sigchld and its declaration
  • error using g_idle_add() in C++, same thing works in C
  • why if else or nested if else are called single statement in C
  • How do I interpret this printf in C
  • load the functions of a shell script without executing it
  • Is FilterSendNetBufferLists handler a must for an NDIS filter to use NdisFSendNetBufferLists?
  • How to write to flash memory using inline assembly?
  • More Return Statements vs. More Indentation
  • How to show an image on a PictureBox from resource?
  • Having malloced some memory,I could't calculator the proper size of the memories I malloced.I don't know why
  • What is the main difference between integer pointer and character pointer?
  • Why are some functions declared extern and header file not included in source in Git source code?
  • what is the use of fflush(stdin) in c programming
  • Is it safe to return file File descriptor locally allocated from another function In C
  • Changing undefined values of an array
  • What does an empty parameter list mean?
  • using strtol on a string literal causing segmentation fault
  • Same structure objects memory overlap?
  • C-Linux-Any way to pass command "history" to Linux shell?
  • Using #define in defining string size C
  • How to use thread pool and message queues in Multithreaded Matrix Multiplication?
  • Can't find how to select path to run a C program
  • Automatic variable in C not initialized but given fixed value within loop
  • main() function defined without return type gives warning
  • Output of following code with integer, float, char variable
  • why buffer memory allocation error in opencl
  • Why am I getting this error during run-time?
  • Strange behaviour of the pow function
  • task in increment , decrement , printf() , why these are evaluated in this manner in C
  • 28 extra bytes in bss
  • Waiting for multiple events without polling
  • Why are my variables reporting as "undeclared identifier" when compiling?
  • Correct AddNode function but somehing happens when I printf
  • When I traverse in the splay tree, then now which one is root?
  • Data type conversion in Postfix evaluation
  • No output in terminal (Head First C)
  • Data writes over after realloc
  • function: findnextchar() doesn't work
  • Getting file-size property from Nautilus
  • Forward declare entities in C standard library?
  • Static array in C
  • Function signature indicates return type void*, but returns pointer of a different type
  • How do I measure time per thread in C?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org